项目作者: nithil

项目描述 :
高级语言: JavaScript
项目地址: git://github.com/nithil/http-exceptions-js.git
创建时间: 2020-05-21T02:36:03Z
项目社区:https://github.com/nithil/http-exceptions-js

开源协议:

下载


http-exceptions-js

Example

  1. const {
  2. BadGatewayException,
  3. BadRequestException,
  4. ConflictException,
  5. ForbiddenException,
  6. GatewayTimeoutException,
  7. InternalServerErrorException,
  8. MethodNotAllowedException,
  9. NotFoundException,
  10. PayloadTooLargeException,
  11. RequestTimeoutException,
  12. ServiceUnavailableException,
  13. UnauthorizedException,
  14. UnprocessableEntityException,
  15. } = require('./src');
  16. * 1
  17. throw new NotFoundException('Record not found');
  18. * 2
  19. const error = new ConflictException('Record already exist with that name');
  20. console.log(error.status); // 409
  21. console.log(error.error); // conflict
  22. console.log(error.message); // Record already exist with that name
  23. | Exception | status | error | message |
  24. | ---------------------------------------- | -------- | --------------------- | ----------- |
  25. | throw new BadRequestException('error') | 400 | Bad Request | error |
  26. | throw new UnauthorizedException() | 401 | Unauthorized | |
  27. | throw new ForbiddenException() | 403 | Forbidden | |
  28. | throw new NotFoundException() | 404 | Not Found | |
  29. | throw new MethodNotAllowedException() | 405 | Method Not Allowed | |
  30. | throw new RequestTimeoutException() | 408 | Request Timeout | |
  31. | throw new ConflictException() | 409 | Conflict | |
  32. | throw new UnprocessableEntityException() | 422 | Unprocessable Entity | |
  33. | throw new InternalServerErrorException() | 500 | Internal Server Error | |
  34. | throw new GatewayTimeoutException() | 502 | Gateway Timeout | |
  35. | throw new ServiceUnavailableException() | 503 | Service Unavailable | |
  36. | throw new BadGatewayException() | 504 | Bad Gateway | |