dw-http-errors 
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');
throw new HttpError(418);
throw new HttpError(418, 'I only brew tea');
Throw custom HTTP exception
const { ImATeapotError } = require('dw-http-errors');
throw new ImATeapotError();
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
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