error.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. const _ = require('lodash');
  2. const util = require('util');
  3. module.exports = {
  4. PermissionError: function (message, previous) {
  5. Error.captureStackTrace(this, this.constructor);
  6. this.name = this.constructor.name;
  7. this.previous = previous;
  8. this.message = 'Permission Denied';
  9. this.public = true;
  10. this.status = 403;
  11. },
  12. ItemNotFoundError: function (id, previous) {
  13. Error.captureStackTrace(this, this.constructor);
  14. this.name = this.constructor.name;
  15. this.previous = previous;
  16. this.message = 'Item Not Found - ' + id;
  17. this.public = true;
  18. this.status = 404;
  19. },
  20. AuthError: function (message, previous) {
  21. Error.captureStackTrace(this, this.constructor);
  22. this.name = this.constructor.name;
  23. this.previous = previous;
  24. this.message = message;
  25. this.public = true;
  26. this.status = 401;
  27. },
  28. InternalError: function (message, previous) {
  29. Error.captureStackTrace(this, this.constructor);
  30. this.name = this.constructor.name;
  31. this.previous = previous;
  32. this.message = message;
  33. this.status = 500;
  34. this.public = false;
  35. },
  36. InternalValidationError: function (message, previous) {
  37. Error.captureStackTrace(this, this.constructor);
  38. this.name = this.constructor.name;
  39. this.previous = previous;
  40. this.message = message;
  41. this.status = 400;
  42. this.public = false;
  43. },
  44. ConfigurationError: function (message, previous) {
  45. Error.captureStackTrace(this, this.constructor);
  46. this.name = this.constructor.name;
  47. this.previous = previous;
  48. this.message = message;
  49. this.status = 400;
  50. this.public = true;
  51. },
  52. CacheError: function (message, previous) {
  53. Error.captureStackTrace(this, this.constructor);
  54. this.name = this.constructor.name;
  55. this.message = message;
  56. this.previous = previous;
  57. this.status = 500;
  58. this.public = false;
  59. },
  60. ValidationError: function (message, previous) {
  61. Error.captureStackTrace(this, this.constructor);
  62. this.name = this.constructor.name;
  63. this.previous = previous;
  64. this.message = message;
  65. this.public = true;
  66. this.status = 400;
  67. },
  68. AssertionFailedError: function (message, previous) {
  69. Error.captureStackTrace(this, this.constructor);
  70. this.name = this.constructor.name;
  71. this.previous = previous;
  72. this.message = message;
  73. this.public = false;
  74. this.status = 400;
  75. },
  76. CommandError: function (stdErr, code, previous) {
  77. Error.captureStackTrace(this, this.constructor);
  78. this.name = this.constructor.name;
  79. this.previous = previous;
  80. this.message = stdErr;
  81. this.code = code;
  82. this.public = false;
  83. },
  84. };
  85. _.forEach(module.exports, function (error) {
  86. util.inherits(error, Error);
  87. });