import { Deprecation } from "deprecation"; import once from "once"; const logOnceCode = once((deprecation) => console.warn(deprecation)); const logOnceHeaders = once((deprecation) => console.warn(deprecation)); class RequestError extends Error { constructor(message, statusCode, options) { super(message); if (Error.captureStackTrace) { Error.captureStackTrace(this, this.constructor); } this.name = "HttpError"; this.status = statusCode; let headers; if ("headers" in options && typeof options.headers !== "undefined") { headers = options.headers; } if ("response" in options) { this.response = options.response; headers = options.response.headers; } const requestCopy = Object.assign({}, options.request); if (options.request.headers.authorization) { requestCopy.headers = Object.assign({}, options.request.headers, { authorization: options.request.headers.authorization.replace( / .*$/, " [REDACTED]" ) }); } requestCopy.url = requestCopy.url.replace(/\bclient_secret=\w+/g, "client_secret=[REDACTED]").replace(/\baccess_token=\w+/g, "access_token=[REDACTED]"); this.request = requestCopy; Object.defineProperty(this, "code", { get() { logOnceCode( new Deprecation( "[@octokit/request-error] `error.code` is deprecated, use `error.status`." ) ); return statusCode; } }); Object.defineProperty(this, "headers", { get() { logOnceHeaders( new Deprecation( "[@octokit/request-error] `error.headers` is deprecated, use `error.response.headers`." ) ); return headers || {}; } }); } } export { RequestError };