You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

62 lines
1.6 KiB

  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. };