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.
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.
- Lambda NodeJS 6.10+
- NodeJS 6+
const resp = ;/* 404 Not Found */throw ;throw "These aren't the droids you're looking for";throw 404;throw 404"These aren't the droids you're looking for";/* 500 Internal Server Error */throw ;throw "Mistakes were made";throw 500;throw 500"Mistakes were made";/* 302 Found */throw "";throw 302"";
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.
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
||Message for the response. A status code and pascal case identifier are prepended. e.g. [NotFound]|
||HTTP status code e.g. 404|
||Pascal case identifier of the HTTP status (e.g. NotFound)|
||Same as statusCode|
||The original non-prepended message|
throw "These aren't the droids you're looking for";
- Returns: NotFoundError
- Message: [NotFound]: These aren't the droids you're looking for