You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

dw-http-errors

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

dw-http-errors

Collection of custom response errors and middleware for express

1.0.0-beta.7
latest
Source
npmnpm
Version published
Weekly downloads
4
300%
Maintainers
1
Weekly downloads
 
Created
Source

dw-http-errors NPM Version

Collection of custom response errors and middleware for express.

Install

npm i dw-http-errors -S

Configure

Add middleware to your application bootstrap file:

const { httpErrorsMiddleware } = require('dw-http-errors');

app.use(httpErrorsMiddleware);

Usage

Throw generic HTTP exception

const { HttpError } = require('dw-http-errors');

// Ex. with default status text
throw new HttpError(418);

// Ex. with custom message
throw new HttpError(418, 'I only brew tea');

Throw custom HTTP exception

const { ImATeapotError } = require('dw-http-errors');

// Ex. with default status text
throw new ImATeapotError();

// Ex. with custom status text
throw new ImATeapotError('I only brew tea');

Exceptions thrown without a message defaults to HTTP standard status text. Exceptions are handled by middle which relays errors as a HTTP response.

Base Exception

  • HttpError

Custom Exceptions

  • BadRequestError
  • UnauthorizedError
  • PaymentRequiredError
  • ForbiddenError
  • NotFoundError
  • MethodNotAllowedError
  • NotAcceptableError
  • ProxyAuthenticationRequiredError
  • RequestTimeoutError
  • ConflictError
  • GoneError
  • LengthRequiredError
  • PreconditionFailedError
  • PayloadTooLargeError
  • URITooLongError
  • UnsupportedMediaTypeError
  • RangeNotSatisfiableError
  • ExpectationFailedError
  • ImATeapotError
  • MisdirectedRequestError
  • UnprocessableEntityError
  • LockedError
  • FailedDependencyError
  • UnorderedCollectionError
  • UpgradeRequiredError
  • PreconditionRequiredError
  • TooManyRequestsError
  • RequestHeaderFieldsTooLargeError
  • UnavailableForLegalReasonsError
  • InternalServerError
  • NotImplementedError
  • BadGatewayError
  • ServiceUnavailableError
  • GatewayTimeoutError
  • HttpVersionNotSupportedError
  • VariantAlsoNegotiatesError
  • InsufficientStorageError
  • LoopDetectedError
  • BandwidthLimitExceededError
  • NotExtendedError
  • NetworkAuthenticationRequiredError

License

MIT

Keywords

http

FAQs

Package last updated on 02 Sep 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts