index.js 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. 'use strict';
  2. Object.defineProperty(exports, '__esModule', { value: true });
  3. function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
  4. var deprecation = require('deprecation');
  5. var once = _interopDefault(require('once'));
  6. const logOnce = once(deprecation => console.warn(deprecation));
  7. /**
  8. * Error with extra properties to help with debugging
  9. */
  10. class RequestError extends Error {
  11. constructor(message, statusCode, options) {
  12. super(message); // Maintains proper stack trace (only available on V8)
  13. /* istanbul ignore next */
  14. if (Error.captureStackTrace) {
  15. Error.captureStackTrace(this, this.constructor);
  16. }
  17. this.name = "HttpError";
  18. this.status = statusCode;
  19. Object.defineProperty(this, "code", {
  20. get() {
  21. logOnce(new deprecation.Deprecation("[@octokit/request-error] `error.code` is deprecated, use `error.status`."));
  22. return statusCode;
  23. }
  24. });
  25. this.headers = options.headers || {}; // redact request credentials without mutating original request options
  26. const requestCopy = Object.assign({}, options.request);
  27. if (options.request.headers.authorization) {
  28. requestCopy.headers = Object.assign({}, options.request.headers, {
  29. authorization: options.request.headers.authorization.replace(/ .*$/, " [REDACTED]")
  30. });
  31. }
  32. requestCopy.url = requestCopy.url // client_id & client_secret can be passed as URL query parameters to increase rate limit
  33. // see https://developer.github.com/v3/#increasing-the-unauthenticated-rate-limit-for-oauth-applications
  34. .replace(/\bclient_secret=\w+/g, "client_secret=[REDACTED]") // OAuth tokens can be passed as URL query parameters, although it is not recommended
  35. // see https://developer.github.com/v3/#oauth2-token-sent-in-a-header
  36. .replace(/\baccess_token=\w+/g, "access_token=[REDACTED]");
  37. this.request = requestCopy;
  38. }
  39. }
  40. exports.RequestError = RequestError;
  41. //# sourceMappingURL=index.js.map