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 = ; app;
Usage
Throw generic HTTP exception
const HttpError = ; // Ex. with default status textthrow 418; // Ex. with custom messagethrow 418 'I only brew tea';
Throw custom HTTP exception
const ImATeapotError = ; // Ex. with default status textthrow ; // Ex. with custom status textthrow '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