http-status.exception.ts 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. export class HttpStatusException extends Error {
  2. constructor(message: string, private code: number) {
  3. super(message);
  4. }
  5. public get statusCode(): number {
  6. return this.code;
  7. }
  8. public get statusText(): string {
  9. return HttpStatusException.getStatusText(this.code);
  10. }
  11. public static getStatusText(code): string {
  12. switch (code) {
  13. case 301:
  14. return 'Moved Permanently';
  15. case 302:
  16. return 'Found';
  17. case 307:
  18. return 'Temporary Redirect';
  19. case 308:
  20. return 'Permanent Redirect';
  21. case 400:
  22. return 'Bad Request';
  23. case 401:
  24. return 'Unauthorized';
  25. case 403:
  26. return 'Forbidden';
  27. case 404:
  28. return 'Not Found';
  29. case 405:
  30. return 'Method Not Allowed';
  31. case 406:
  32. return 'Not Acceptable';
  33. case 500:
  34. return 'Internal Server Error';
  35. case 501:
  36. return 'Not Implemented';
  37. case 502:
  38. return 'Bad Gateway';
  39. case 503:
  40. return 'Service Unavailable';
  41. default:
  42. return 'Unknown Error';
  43. }
  44. }
  45. }