fetch-error.js 781 B

123456789101112131415161718192021222324252627282930313233
  1. /**
  2. * fetch-error.js
  3. *
  4. * FetchError interface for operational errors
  5. */
  6. module.exports = FetchError;
  7. /**
  8. * Create FetchError instance
  9. *
  10. * @param String message Error message for human
  11. * @param String type Error type for machine
  12. * @param String systemError For Node.js system error
  13. * @return FetchError
  14. */
  15. function FetchError(message, type, systemError) {
  16. this.name = this.constructor.name;
  17. this.message = message;
  18. this.type = type;
  19. // when err.type is `system`, err.code contains system error code
  20. if (systemError) {
  21. this.code = this.errno = systemError.code;
  22. }
  23. // hide custom error implementation details from end-users
  24. Error.captureStackTrace(this, this.constructor);
  25. }
  26. require('util').inherits(FetchError, Error);