npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

watios

v1.0.1

Published

A lightweight Axios wrapper with enhanced error handling and WhatsApp integration for reporting.

Downloads

8

Readme

Watios

Watios is a lightweight Axios wrapper designed for enhanced error handling with real-time WhatsApp integration. It simplifies the process of handling errors in HTTP requests by sending detailed alerts directly to your WhatsApp in case of failures. Watios offers flexibility, detailed error reporting, and a seamless way to stay updated about issues in your API requests.

Features

  • Axios-based: Utilizes Axios to make HTTP requests.
  • Error Notifications: Sends error details to a specified WhatsApp number.
  • Real-time Alerts: Instantly informs you of issues like failed requests, timeouts, and connection errors.
  • Customizable Configuration: Easily configure timeout, headers, and more.
  • Duplicate Error Prevention: Prevents sending the same error message multiple times within 3 minutes.
  • CommonJS and ESM: Supports both require and import styles.

Installation

Install the package using npm:

bash npm install watios

Usage

  1. Setting Up Watios First, you need to import and set up the Watios instance by providing a phone number and a passkey for validation. You will get the passkey from the watios-dashboard.
import { createWatios, watiosAlert } from 'watios';

const watios = createWatios({
  phonenumber: '919778715634', // Your WhatsApp number (with country code)
  passkey: 'your_passkey'       // Passkey for validation (set in your .env file)
});
  1. Making API Requests Watios uses Axios under the hood, so you can use it to make HTTP requests in the same way. Here’s an example of making a POST request:

const requestBody = {
  key: 'value'
};

watios.post('https://api.example.com/data', requestBody)
  .then(response => {
    console.log('Success:', response.data);
  })
  .catch(error => {
    watiosAlert(error); // Sends the error details to WhatsApp
  });

Error Handling

Watios is built to handle errors seamlessly. It will automatically send detailed error information to your specified WhatsApp number if an Axios request fails:

try {
  // Trigger an error (e.g., calling an undefined function)
  const result = nonExistentFunction();
} catch (error) {
  watiosAlert(error); // Sends general errors to WhatsApp
}
  1. Preventing Duplicate Errors Watios includes a mechanism to prevent sending the same error multiple times within a 3-minute window. This is useful for avoiding spam if the same error repeatedly occurs in a short span.

  2. Handling Axios-Specific and General Errors Watios can handle both Axios-specific errors (e.g., network issues, server errors) and general JavaScript errors (e.g., reference errors, type errors).

Here’s an example of how it handles multiple types of errors:

try {
  // API request that might fail
  await watios.get('https://api.example.com/fail');
} catch (error) {
  watiosAlert(error); // Sends the error to WhatsApp
}

Environment Variables

For security, Watios relies on environment variables to store sensitive information. Make sure to set the following in your .env file:

PASSKEY=your_secure_passkey

Configuration

Options for createWatios

| Option | Type | Description | |---------------|----------|---------------------------------------------------------------| | phonenumber | string | The WhatsApp number where errors will be sent (with country code). | | passkey | string | A passkey used for validation (recommended to set in .env). |

Rollup Build

Watios is bundled using Rollup, and it supports both CommonJS and ES module formats. You can build the package with:

npm run build

This will output the following:

dist/index.cjs.js: CommonJS version dist/index.esm.js: ES Module version

Importing and Requiring Watios

You can import Watios in either ES module or CommonJS format:

  • ES Module:

import { createWatios, watiosAlert } from 'watios';

  • CommonJS:

const { createWatios, watiosAlert } = require('watios');

License

This project is licensed under the MIT License. See the LICENSE file for details.