Skip to content

Commit 68bdbc4

Browse files
authored
fix: replace ./src/http-error with @octokit/request-error (#58)
1 parent 0bb7016 commit 68bdbc4

File tree

5 files changed

+26
-99
lines changed

5 files changed

+26
-99
lines changed

package-lock.json

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
"homepage": "https://github.com/octokit/request.js#readme",
3333
"dependencies": {
3434
"@octokit/endpoint": "^5.1.0",
35+
"@octokit/request-error": "^1.0.1",
3536
"deprecation": "^2.0.0",
3637
"is-plain-object": "^3.0.0",
3738
"node-fetch": "^2.3.0",

src/fetch-wrapper.ts

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import isPlainObject from "is-plain-object";
22
import nodeFetch from "node-fetch";
3+
import { RequestError } from "@octokit/request-error";
34

45
import getBuffer from "./get-buffer-response";
5-
import HttpError from "./http-error";
66
import { endpoint } from "./types";
77

88
export default function fetchWrapper(
@@ -52,29 +52,28 @@ export default function fetchWrapper(
5252
return;
5353
}
5454

55-
throw new HttpError(
56-
response.statusText,
57-
status,
55+
throw new RequestError(response.statusText, status, {
5856
headers,
59-
requestOptions
60-
);
57+
request: requestOptions
58+
});
6159
}
6260

6361
if (status === 304) {
64-
throw new HttpError("Not modified", status, headers, requestOptions);
62+
throw new RequestError("Not modified", status, {
63+
headers,
64+
request: requestOptions
65+
});
6566
}
6667

6768
if (status >= 400) {
6869
return response
6970
.text()
7071

7172
.then(message => {
72-
const error = new HttpError(
73-
message,
74-
status,
73+
const error = new RequestError(message, status, {
7574
headers,
76-
requestOptions
77-
);
75+
request: requestOptions
76+
});
7877

7978
try {
8079
Object.assign(error, JSON.parse(error.message));
@@ -108,10 +107,13 @@ export default function fetchWrapper(
108107
})
109108

110109
.catch(error => {
111-
if (error instanceof HttpError) {
110+
if (error instanceof RequestError) {
112111
throw error;
113112
}
114113

115-
throw new HttpError(error.message, 500, headers, requestOptions);
114+
throw new RequestError(error.message, 500, {
115+
headers,
116+
request: requestOptions
117+
});
116118
});
117119
}

src/http-error.ts

Lines changed: 0 additions & 61 deletions
This file was deleted.

test/request.test.ts

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -425,30 +425,6 @@ describe("request()", () => {
425425
);
426426
});
427427
});
428-
429-
it("error.code (deprecated)", () => {
430-
const mock = fetchMock.sandbox().get("path:/orgs/nope", 404);
431-
432-
const consoleWarn = console.warn;
433-
let warnCalled = 0;
434-
console.warn = () => warnCalled++;
435-
return request("GET /orgs/:org", {
436-
org: "nope",
437-
request: {
438-
fetch: mock
439-
}
440-
})
441-
.then(() => {
442-
throw new Error("should not resolve");
443-
})
444-
445-
.catch(error => {
446-
expect(error.code).toEqual(404);
447-
expect(warnCalled).toEqual(1);
448-
console.warn = consoleWarn;
449-
});
450-
});
451-
452428
it("Just URL", () => {
453429
const mock = fetchMock.sandbox().get("path:/", 200);
454430

0 commit comments

Comments
 (0)