@octokit/request-error
Advanced tools
Comparing version 2.0.6 to 2.1.0
@@ -10,3 +10,4 @@ 'use strict'; | ||
const logOnce = once(deprecation => console.warn(deprecation)); | ||
const logOnceCode = once(deprecation => console.warn(deprecation)); | ||
const logOnceHeaders = once(deprecation => console.warn(deprecation)); | ||
/** | ||
@@ -28,11 +29,14 @@ * Error with extra properties to help with debugging | ||
this.status = statusCode; | ||
Object.defineProperty(this, "code", { | ||
get() { | ||
logOnce(new deprecation.Deprecation("[@octokit/request-error] `error.code` is deprecated, use `error.status`.")); | ||
return statusCode; | ||
} | ||
let headers; | ||
}); | ||
this.headers = options.headers || {}; // redact request credentials without mutating original request options | ||
if ("headers" in options && typeof options.headers !== "undefined") { | ||
headers = options.headers; | ||
} | ||
if ("response" in options) { | ||
this.response = options.response; | ||
headers = options.response.headers; | ||
} // redact request credentials without mutating original request options | ||
const requestCopy = Object.assign({}, options.request); | ||
@@ -51,3 +55,18 @@ | ||
.replace(/\baccess_token=\w+/g, "access_token=[REDACTED]"); | ||
this.request = requestCopy; | ||
this.request = requestCopy; // deprecations | ||
Object.defineProperty(this, "code", { | ||
get() { | ||
logOnceCode(new deprecation.Deprecation("[@octokit/request-error] `error.code` is deprecated, use `error.status`.")); | ||
return statusCode; | ||
} | ||
}); | ||
Object.defineProperty(this, "headers", { | ||
get() { | ||
logOnceHeaders(new deprecation.Deprecation("[@octokit/request-error] `error.headers` is deprecated, use `error.response.headers`.")); | ||
return headers || {}; | ||
} | ||
}); | ||
} | ||
@@ -54,0 +73,0 @@ |
import { Deprecation } from "deprecation"; | ||
import once from "once"; | ||
const logOnce = once((deprecation) => console.warn(deprecation)); | ||
const logOnceCode = once((deprecation) => console.warn(deprecation)); | ||
const logOnceHeaders = once((deprecation) => console.warn(deprecation)); | ||
/** | ||
@@ -17,9 +18,10 @@ * Error with extra properties to help with debugging | ||
this.status = statusCode; | ||
Object.defineProperty(this, "code", { | ||
get() { | ||
logOnce(new Deprecation("[@octokit/request-error] `error.code` is deprecated, use `error.status`.")); | ||
return statusCode; | ||
}, | ||
}); | ||
this.headers = options.headers || {}; | ||
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; | ||
} | ||
// redact request credentials without mutating original request options | ||
@@ -40,3 +42,16 @@ const requestCopy = Object.assign({}, options.request); | ||
this.request = requestCopy; | ||
// deprecations | ||
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 || {}; | ||
}, | ||
}); | ||
} | ||
} |
@@ -1,2 +0,2 @@ | ||
import { RequestOptions, ResponseHeaders } from "@octokit/types"; | ||
import { RequestOptions, ResponseHeaders, OctokitResponse } from "@octokit/types"; | ||
import { RequestErrorOptions } from "./types"; | ||
@@ -19,10 +19,16 @@ /** | ||
/** | ||
* Request options that lead to the error. | ||
*/ | ||
request: RequestOptions; | ||
/** | ||
* error response headers | ||
* | ||
* @deprecated `error.headers` is deprecated in favor of `error.response.headers` | ||
*/ | ||
headers: ResponseHeaders; | ||
/** | ||
* Request options that lead to the error. | ||
* Response object if a response was received | ||
*/ | ||
request: RequestOptions; | ||
response?: OctokitResponse<unknown>; | ||
constructor(message: string, statusCode: number, options: RequestErrorOptions); | ||
} |
@@ -1,5 +0,9 @@ | ||
import { RequestOptions, ResponseHeaders } from "@octokit/types"; | ||
import { RequestOptions, ResponseHeaders, OctokitResponse } from "@octokit/types"; | ||
export declare type RequestErrorOptions = { | ||
/** @deprecated set `response` instead */ | ||
headers?: ResponseHeaders; | ||
request: RequestOptions; | ||
} | { | ||
response: OctokitResponse<unknown>; | ||
request: RequestOptions; | ||
}; |
import { Deprecation } from 'deprecation'; | ||
import once from 'once'; | ||
const logOnce = once((deprecation) => console.warn(deprecation)); | ||
const logOnceCode = once((deprecation) => console.warn(deprecation)); | ||
const logOnceHeaders = once((deprecation) => console.warn(deprecation)); | ||
/** | ||
@@ -18,9 +19,10 @@ * Error with extra properties to help with debugging | ||
this.status = statusCode; | ||
Object.defineProperty(this, "code", { | ||
get() { | ||
logOnce(new Deprecation("[@octokit/request-error] `error.code` is deprecated, use `error.status`.")); | ||
return statusCode; | ||
}, | ||
}); | ||
this.headers = options.headers || {}; | ||
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; | ||
} | ||
// redact request credentials without mutating original request options | ||
@@ -41,2 +43,15 @@ const requestCopy = Object.assign({}, options.request); | ||
this.request = requestCopy; | ||
// deprecations | ||
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 || {}; | ||
}, | ||
}); | ||
} | ||
@@ -43,0 +58,0 @@ } |
{ | ||
"name": "@octokit/request-error", | ||
"description": "Error class for Octokit request errors", | ||
"version": "2.0.6", | ||
"version": "2.1.0", | ||
"license": "MIT", | ||
@@ -6,0 +6,0 @@ "files": [ |
@@ -58,3 +58,2 @@ # http-error.js | ||
error.status; // 500 | ||
error.headers; // { 'x-github-request-id': '1:2:3:4' } | ||
error.request.method; // POST | ||
@@ -64,2 +63,3 @@ error.request.url; // https://api.github.com/foo | ||
error.request.headers; // { authorization: 'token [REDACTED]' } | ||
error.response; // { url, status, headers, data } | ||
``` | ||
@@ -66,0 +66,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
21914
210