github.com/jfrog/frogbot@v1.1.1-0.20231221090046-821a26f50338/action/node_modules/@octokit/request-error/dist-node/index.js (about) 1 'use strict'; 2 3 Object.defineProperty(exports, '__esModule', { value: true }); 4 5 function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; } 6 7 var deprecation = require('deprecation'); 8 var once = _interopDefault(require('once')); 9 10 const logOnceCode = once(deprecation => console.warn(deprecation)); 11 const logOnceHeaders = once(deprecation => console.warn(deprecation)); 12 /** 13 * Error with extra properties to help with debugging 14 */ 15 16 class RequestError extends Error { 17 constructor(message, statusCode, options) { 18 super(message); // Maintains proper stack trace (only available on V8) 19 20 /* istanbul ignore next */ 21 22 if (Error.captureStackTrace) { 23 Error.captureStackTrace(this, this.constructor); 24 } 25 26 this.name = "HttpError"; 27 this.status = statusCode; 28 let headers; 29 30 if ("headers" in options && typeof options.headers !== "undefined") { 31 headers = options.headers; 32 } 33 34 if ("response" in options) { 35 this.response = options.response; 36 headers = options.response.headers; 37 } // redact request credentials without mutating original request options 38 39 40 const requestCopy = Object.assign({}, options.request); 41 42 if (options.request.headers.authorization) { 43 requestCopy.headers = Object.assign({}, options.request.headers, { 44 authorization: options.request.headers.authorization.replace(/ .*$/, " [REDACTED]") 45 }); 46 } 47 48 requestCopy.url = requestCopy.url // client_id & client_secret can be passed as URL query parameters to increase rate limit 49 // see https://developer.github.com/v3/#increasing-the-unauthenticated-rate-limit-for-oauth-applications 50 .replace(/\bclient_secret=\w+/g, "client_secret=[REDACTED]") // OAuth tokens can be passed as URL query parameters, although it is not recommended 51 // see https://developer.github.com/v3/#oauth2-token-sent-in-a-header 52 .replace(/\baccess_token=\w+/g, "access_token=[REDACTED]"); 53 this.request = requestCopy; // deprecations 54 55 Object.defineProperty(this, "code", { 56 get() { 57 logOnceCode(new deprecation.Deprecation("[@octokit/request-error] `error.code` is deprecated, use `error.status`.")); 58 return statusCode; 59 } 60 61 }); 62 Object.defineProperty(this, "headers", { 63 get() { 64 logOnceHeaders(new deprecation.Deprecation("[@octokit/request-error] `error.headers` is deprecated, use `error.response.headers`.")); 65 return headers || {}; 66 } 67 68 }); 69 } 70 71 } 72 73 exports.RequestError = RequestError; 74 //# sourceMappingURL=index.js.map