Skip to content

Commit

Permalink
feat: set error.response (#64)
Browse files Browse the repository at this point in the history
  • Loading branch information
gr2m committed Jun 12, 2021
1 parent e9d820f commit 59cf96f
Show file tree
Hide file tree
Showing 8 changed files with 587 additions and 579 deletions.
2 changes: 1 addition & 1 deletion HOW_IT_WORKS.md
Expand Up @@ -127,7 +127,7 @@ octokit.hook.after("request", async (response, options) => {
});
octokit.hook.error("request", async (error, options) => {
if (error.status === 304) {
return findInCache(error.headers.etag);
return findInCache(error.response.headers.etag);
}

throw error;
Expand Down
2 changes: 1 addition & 1 deletion docs/src/pages/api/06_hooks.md
Expand Up @@ -13,7 +13,7 @@ octokit.hook.after("request", async (response, options) => {
});
octokit.hook.error("request", async (error, options) => {
if (error.status === 304) {
return findInCache(error.headers.etag);
return findInCache(error.response.headers.etag);
}

throw error;
Expand Down
1,148 changes: 578 additions & 570 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -32,7 +32,7 @@
],
"repository": "github:octokit/rest.js",
"dependencies": {
"@octokit/core": "^3.2.3",
"@octokit/core": "^3.5.0",
"@octokit/plugin-paginate-rest": "^2.6.2",
"@octokit/plugin-request-log": "^1.0.2",
"@octokit/plugin-rest-endpoint-methods": "5.3.1"
Expand Down
4 changes: 2 additions & 2 deletions test/integration/deprecations-test.js
Expand Up @@ -422,7 +422,7 @@ describe("deprecations", () => {
"2FA required, but options.on2fa is not a function. See https://github.com/octokit/rest.js#authentication"
);
expect(error.status).to.equal(401);
expect(!!error.headers).to.equal(true);
expect(!!error.response.headers).to.equal(true);
expect(!!error.request).to.equal(true);
});
});
Expand Down Expand Up @@ -977,7 +977,7 @@ describe("deprecations", () => {
"2FA required, but options.on2fa is not a function. See https://github.com/octokit/rest.js#authentication"
);
expect(error.status).to.equal(401);
expect(!!error.headers).to.equal(true);
expect(!!error.response.headers).to.equal(true);
expect(!!error.request).to.equal(true);
});
});
Expand Down
2 changes: 1 addition & 1 deletion test/integration/request-errors-test.js
Expand Up @@ -103,7 +103,7 @@ describe("request errors", () => {
.catch((error) => {
expect(error.name).to.equal("HttpError");
expect(error.status).to.equal(401);
expect(error.headers).to.deep.equal({
expect(error.response.headers).to.deep.equal({
"content-type": "application/json",
"x-foo": "bar",
});
Expand Down
4 changes: 2 additions & 2 deletions test/scenarios/errors.test.ts
Expand Up @@ -24,14 +24,14 @@ describe("api.github.com", () => {
expect(error.message).toEqual(
`Validation Failed: {"resource":"Label","code":"invalid","field":"color"}`
);
expect(error.errors).toStrictEqual([
expect(error.response.data.errors).toStrictEqual([
{
resource: "Label",
code: "invalid",
field: "color",
},
]);
expect(error.documentation_url).toMatch(
expect(error.response.data.documentation_url).toMatch(
new RegExp("rest/reference/issues#create-a-label")
);
});
Expand Down
2 changes: 1 addition & 1 deletion test/typescript-validate.ts
Expand Up @@ -100,7 +100,7 @@ export default async function () {
// @ts-expect-error TODO: .error hook should accept a return of a valid response
octokit.hook.error("request", async (error, options) => {
if ("status" in error && error.status === 304) {
return findInCache(error.headers.etag);
return findInCache(error.response.headers.etag);
}

throw error;
Expand Down

0 comments on commit 59cf96f

Please sign in to comment.