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 |
|
14 |
|
15 |
|
16 | class RequestError extends Error {
|
17 | constructor(message, statusCode, options) {
|
18 | super(message);
|
19 |
|
20 |
|
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 | }
|
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
|
49 |
|
50 | .replace(/\bclient_secret=\w+/g, "client_secret=[REDACTED]")
|
51 |
|
52 | .replace(/\baccess_token=\w+/g, "access_token=[REDACTED]");
|
53 | this.request = requestCopy;
|
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 |
|