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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@supersourcing/response-handler

v1.0.0

Published

To handle api's response status & errors

Downloads

17

Readme

response-handler

Version npm It is a simple response message package.

Installation

To install the project, you need to have NodeJS and Npm pre-installed in your system. Only then, you can run the following commands:

       npm install response-handler

Description

  • index.js - This file contains the code for error and response handle.

  • notFoundError - It indicates that the URL you used in your request doesn’t exist on the API server, or origin server.this can also indicate a server problem. Sometimes API URL paths change after a version update, but sometimes they change because something on the server went wrong.

          notFoundError('Your message!', yourData); // 404
  • forbiddenError - The forbidden status indicates that you don’t have permission to request that URL. You’re authenticated, but the user or role you’re authenticated for isn’t permitted to make the API request.This also occurs when you have an authentication issue, like when using the wrong API key or trying to access features your subscription plan doesn’t allow for.

          forbiddenError('Your message!', yourData); // 403
  • unauthorizedError - This status code means you haven’t yet authenticated against the API. The API doesn’t know who you are and it won’t serve you. For most APIs you need to sign up and get an API key. This key is then used inside an HTTP header field when you send a request, telling the API who you are.

          unauthorizedError('Your message!', yourData); // 401
  • preconditionFailedError - The client has indicated preconditions in its headers which the server does not meet.

          preconditionFailedError('Your message!', yourData); // 412
  • tooManyRequestsError - Most API subscription plans have limits — the cheaper the plan, the fewer requests per second are allowed for your API key.

          tooManyRequestsError('Your message!', yourData); // 429
  • internalServerError - This HTTP status code can mean anything really, but it usually indicates the API server crashed. It could have been caused by something related to your API call.

          internalServerError('Your message!', yourData); // 500
  • notImplementedError - Usually, an HTTP request with an inappropriate method simply results in a 404 not found status. A not-implemented status implies that the method isn’t implemented “yet.” The API creator can use this status to tell the clients that this method will be available to them in future requests.

          notImplementedError('Your message!', yourData); // 501
  • badGatewayError - This response tells you that the server you were calling wasn’t the actual API server, but a gateway or proxy. The proxy server tries to call the API server in your name. This error response also indicates that the API server didn’t answer. This could be related to a network problem, or simply because the API server crashed, or was down for maintenance

          badGatewayError('Your message!', yourData); // 502
  • serviceUnavailableError - The 503 Service Unavailable Status indicates a server error. Too many API requests were sent and now the API can’t handle any more of them. This problem solves itself when clients send fewer future requests, but it could also mean that the API provider didn’t plan enough resources for all of its customers.

          serviceUnavailableError('Your message!', yourData); // 503
  • gatewayTimedOutError - Like the 502 Bad Gateway status, this response code tells you that the server you were calling is a proxy for the real API server. This time, the problem is the API server’s slow response. This could be related to high network latency between the proxy and the API server. It could also mean that the API server takes too long to process your request.To solve this problem, check if your request’s content could be related to that timeout. If you are requesting too much data or a calculation that takes too long, you should try and reduce it. If you think your request is reasonable and the status doesn’t go away, contact support.

          gatewayTimedOutError('Your message!', yourData); // 504
  • badRequestError - The request could not be understood by the server due to incorrect syntax. The client SHOULD NOT repeat the request without modifications.

          badRequestError('Your message!', yourData); // 400
  • Unprocessable Entity - The server understands the content type and syntax of the request entity, but still server is unable to process the request for some reason.

          unProcessableEntity('Your message!', yourData); // 422
  • Ok Response - OK success status response code indicates that the request has succeeded. A 200 response is cacheable by default. The meaning of a success depends on the HTTP request method: GET : The resource has been fetched and is transmitted in the message body.

          okResponse(yourData, 'Your message!'); // 200

Usage

  • In your file

    const responseFunction = require('@mayank_supersourcing/response-handler');
    
    const your_function_name = async () => {
        try {
            const data = your_conditions;
            if (data) {
                return responseFunction.okResponse(data, 'Your message!');
        } catch (error) {
            return responseFunction.unProcessableEntity(error.message);
        }
    };
  • Ok Response

    {
        "success": true,
        "statusCode": 200,
        "data": [],
        "message": "Your message!"
    }
  • Un Processable Entity Response

    {
        "statusCode": 422,
        "message": "Your message!"
    }