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

aws-apig-responses

v2.0.10

Published

A Error derived object factory designed to provide an easy map to AWS API Gateway error regex.

Downloads

24

Readme

aws-apig-responses

npm Build Status codecov dependencies Status devDependencies Status Greenkeeper badge Inline docs

A Error derived object factory designed to provide an easy map to AWS API Gateway error regex. This is accomplished through prepending the status code (e.g. 404) and pascal code id (e.g. NotFound) to the Error message.

Supports client (e.g. 404), server (e.g. 500), and non errors (e.g. 302) for maximum flexibility. Utilizes Nodes built-in HTTP module for status codes and descriptions.

Contribution

I welcome bug reports, feature requests, and pull requests to improve the module! Can't guarantee they'll necessarily be implemented/incorporated, but will do my best to consider. If you do plan a pull request for a larger feature, please create an issue to discuss first.

Supported Runtimes

  • NodeJS 10+

Usage

const resp = require("aws-apig-responses");

/* 404 Not Found */
throw new resp.NotFound();
throw new resp.NotFound("These aren't the droids you're looking for");
throw new resp[404]();
throw new resp[404]("These aren't the droids you're looking for");

/* 500 Internal Server Error */
throw new resp.InternalServerError();
throw new resp.InternalServerError("Mistakes were made");
throw new resp[500]();
throw new resp[500]("Mistakes were made");

/* 302 Found */
throw new resp.Found("https://redirect-me-here12345.com");
throw new resp[302]("https://redirect-me-here12345.com");

NOTE: 302 does not return the Location header natively, but is intended to provide a location for the URL that can be referenced in a mapping template

All HTTP codes are available either using the pascal case name (e.g. BadRequest, ServiceUnavailable, etc. [including ImATeapot!]) or numeric code. For a full list, please reference http.STATUS_CODES in the Node HTTP module documentation.

Upon invoking new, a subclass of HttpError, which is a subclass of Error, with the prepended message is returned. Details below.

HttpError

Base class for the specific HTTP errors Supports non-errors, such as 302 Redirect, but since API Gateway requires an Error, this extends Error and is named accordingly

Kind: global class
Properties

| Name | Type | Description | | --- | --- | --- | | message | string | Message for the response. A status code and pascal case identifier are prepended. e.g. [404][NotFound] | | statusCode | string | HTTP status code e.g. 404 | | statusId | string | Pascal case identifier of the HTTP status (e.g. NotFound) | | status | string | Same as statusCode | | origMessage | string | The original non-prepended message |

Example

throw new resp.NotFound("These aren't the droids you're looking for");
  • Returns: NotFoundError
  • Message: [404][NotFound]: These aren't the droids you're looking for