A preset of HTTP errors that can be easily used to throw errors in your applications.
npm i easy-http-errors --save
yarn add easy-http-errors
// ES6 import.
import { BadRequestError } from 'easy-http-errors';
// Throw the default bad request.
throw new BadRequestError();
// Throw a bad request with a custom message and properties.
throw new BadRequestError('Ups, this is a bad request', { foo: 'bar' });
Status Code | Name |
---|---|
400 | BadRequestError |
401 | UnauthorizedError |
402 | PaymentRequiredError |
403 | ForbiddenError |
404 | NotFoundError |
405 | MethodNotAllowedError |
406 | NotAcceptableError |
407 | ProxyAuthenticationRequiredError |
408 | RequestTimeoutError |
409 | ConflictError |
410 | GoneError |
411 | LengthRequiredError |
412 | PreconditionFailedError |
413 | PayloadTooLargeError |
414 | URITooLongError |
415 | UnsupportedMediaTypeError |
416 | RangeNotSatisfiableError |
417 | ExpectationFailedError |
418 | ImATeapotError |
421 | MisdirectedRequestError |
422 | UnprocessableEntityError |
423 | LockedError |
424 | FailedDependencyError |
425 | UnorderedCollectionError |
426 | UpgradeRequiredError |
428 | PreconditionRequiredError |
429 | TooManyRequestsError |
431 | RequestHeaderFieldsTooLargeError |
451 | UnavailableForLegalReasonsError |
500 | InternalServerError |
501 | NotImplementedError |
502 | BadGatewayError |
503 | ServiceUnavailableError |
504 | GatewayTimeoutError |
505 | HTTPVersionNotSupportedError |
506 | VariantAlsoNegotiatesError |
507 | InsufficientStorageError |
508 | LoopDetectedError |
509 | BandwidthLimitExceededError |
510 | NotExtendedError |
511 | NetworkAuthenticationRequiredError |
Run the tests from the root directory:
npm test
Found a bug or want to suggest something? Take a look first on the current and closed issues. If it is something new, please submit an issue.
It will be awesome if you can help us evolve easy-http-errors
. Want to help?
- Fork it.
npm install
.- Hack away.
- Run the tests:
npm test
. - Create a Pull Request.