2022-01-21 08:28:41 +00:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
|
|
|
|
|
function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
|
|
|
|
|
|
|
|
var deprecation = require('deprecation');
|
|
|
|
var once = _interopDefault(require('once'));
|
|
|
|
|
2022-06-08 10:36:39 +00:00
|
|
|
const logOnceCode = once(deprecation => console.warn(deprecation));
|
|
|
|
const logOnceHeaders = once(deprecation => console.warn(deprecation));
|
2022-01-21 08:28:41 +00:00
|
|
|
/**
|
|
|
|
* Error with extra properties to help with debugging
|
|
|
|
*/
|
2023-08-17 09:47:40 +00:00
|
|
|
|
2022-01-21 08:28:41 +00:00
|
|
|
class RequestError extends Error {
|
|
|
|
constructor(message, statusCode, options) {
|
2023-08-17 09:47:40 +00:00
|
|
|
super(message); // Maintains proper stack trace (only available on V8)
|
|
|
|
|
2022-01-21 08:28:41 +00:00
|
|
|
/* istanbul ignore next */
|
2023-08-17 09:47:40 +00:00
|
|
|
|
2022-01-21 08:28:41 +00:00
|
|
|
if (Error.captureStackTrace) {
|
|
|
|
Error.captureStackTrace(this, this.constructor);
|
|
|
|
}
|
2023-08-17 09:47:40 +00:00
|
|
|
|
2022-01-21 08:28:41 +00:00
|
|
|
this.name = "HttpError";
|
|
|
|
this.status = statusCode;
|
2022-06-08 10:36:39 +00:00
|
|
|
let headers;
|
2023-08-17 09:47:40 +00:00
|
|
|
|
2022-06-08 10:36:39 +00:00
|
|
|
if ("headers" in options && typeof options.headers !== "undefined") {
|
|
|
|
headers = options.headers;
|
|
|
|
}
|
2023-08-17 09:47:40 +00:00
|
|
|
|
2022-06-08 10:36:39 +00:00
|
|
|
if ("response" in options) {
|
|
|
|
this.response = options.response;
|
|
|
|
headers = options.response.headers;
|
2023-08-17 09:47:40 +00:00
|
|
|
} // redact request credentials without mutating original request options
|
|
|
|
|
|
|
|
|
2022-01-21 08:28:41 +00:00
|
|
|
const requestCopy = Object.assign({}, options.request);
|
2023-08-17 09:47:40 +00:00
|
|
|
|
2022-01-21 08:28:41 +00:00
|
|
|
if (options.request.headers.authorization) {
|
|
|
|
requestCopy.headers = Object.assign({}, options.request.headers, {
|
|
|
|
authorization: options.request.headers.authorization.replace(/ .*$/, " [REDACTED]")
|
|
|
|
});
|
|
|
|
}
|
2023-08-17 09:47:40 +00:00
|
|
|
|
|
|
|
requestCopy.url = requestCopy.url // client_id & client_secret can be passed as URL query parameters to increase rate limit
|
2022-01-21 08:28:41 +00:00
|
|
|
// see https://developer.github.com/v3/#increasing-the-unauthenticated-rate-limit-for-oauth-applications
|
2023-08-17 09:47:40 +00:00
|
|
|
.replace(/\bclient_secret=\w+/g, "client_secret=[REDACTED]") // OAuth tokens can be passed as URL query parameters, although it is not recommended
|
2022-01-21 08:28:41 +00:00
|
|
|
// see https://developer.github.com/v3/#oauth2-token-sent-in-a-header
|
|
|
|
.replace(/\baccess_token=\w+/g, "access_token=[REDACTED]");
|
2023-08-17 09:47:40 +00:00
|
|
|
this.request = requestCopy; // deprecations
|
|
|
|
|
2022-06-08 10:36:39 +00:00
|
|
|
Object.defineProperty(this, "code", {
|
|
|
|
get() {
|
|
|
|
logOnceCode(new deprecation.Deprecation("[@octokit/request-error] `error.code` is deprecated, use `error.status`."));
|
|
|
|
return statusCode;
|
|
|
|
}
|
2023-08-17 09:47:40 +00:00
|
|
|
|
2022-06-08 10:36:39 +00:00
|
|
|
});
|
|
|
|
Object.defineProperty(this, "headers", {
|
|
|
|
get() {
|
|
|
|
logOnceHeaders(new deprecation.Deprecation("[@octokit/request-error] `error.headers` is deprecated, use `error.response.headers`."));
|
|
|
|
return headers || {};
|
|
|
|
}
|
2023-08-17 09:47:40 +00:00
|
|
|
|
2022-06-08 10:36:39 +00:00
|
|
|
});
|
2022-01-21 08:28:41 +00:00
|
|
|
}
|
2023-08-17 09:47:40 +00:00
|
|
|
|
2022-01-21 08:28:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
exports.RequestError = RequestError;
|
|
|
|
//# sourceMappingURL=index.js.map
|