errors.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. 'use strict';
  2. function RequestError(cause, options, response) {
  3. this.name = 'RequestError';
  4. this.message = String(cause);
  5. this.cause = cause;
  6. this.error = cause; // legacy attribute
  7. this.options = options;
  8. this.response = response;
  9. if (Error.captureStackTrace) { // required for non-V8 environments
  10. Error.captureStackTrace(this);
  11. }
  12. }
  13. RequestError.prototype = Object.create(Error.prototype);
  14. RequestError.prototype.constructor = RequestError;
  15. function StatusCodeError(statusCode, body, options, response) {
  16. this.name = 'StatusCodeError';
  17. this.statusCode = statusCode;
  18. this.message = statusCode + ' - ' + (JSON && JSON.stringify ? JSON.stringify(body) : body);
  19. this.error = body; // legacy attribute
  20. this.options = options;
  21. this.response = response;
  22. if (Error.captureStackTrace) { // required for non-V8 environments
  23. Error.captureStackTrace(this);
  24. }
  25. }
  26. StatusCodeError.prototype = Object.create(Error.prototype);
  27. StatusCodeError.prototype.constructor = StatusCodeError;
  28. function TransformError(cause, options, response) {
  29. this.name = 'TransformError';
  30. this.message = String(cause);
  31. this.cause = cause;
  32. this.error = cause; // legacy attribute
  33. this.options = options;
  34. this.response = response;
  35. if (Error.captureStackTrace) { // required for non-V8 environments
  36. Error.captureStackTrace(this);
  37. }
  38. }
  39. TransformError.prototype = Object.create(Error.prototype);
  40. TransformError.prototype.constructor = TransformError;
  41. module.exports = {
  42. RequestError: RequestError,
  43. StatusCodeError: StatusCodeError,
  44. TransformError: TransformError
  45. };