Skip to content

Commit 1a3f1c0

Browse files
authored
Merge pull request #4 from hey-api/fix/request-timeout
fix: allow passing timeout value to sendRequest
2 parents 4743034 + e5c19c0 commit 1a3f1c0

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

lib/resolvers/url.ts

+9-1
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@ import type { FileInfo } from "../types/index.js";
66
export const sendRequest = async ({
77
init,
88
redirects = [],
9+
timeout = 60_000,
910
url,
1011
}: {
1112
init?: RequestInit;
1213
redirects?: string[];
14+
timeout?: number;
1315
url: URL | string;
1416
}): Promise<{
1517
response: Response;
@@ -21,14 +23,19 @@ export const sendRequest = async ({
2123
const controller = new AbortController();
2224
const timeoutId = setTimeout(() => {
2325
controller.abort();
24-
}, 60_000);
26+
}, timeout);
2527
const response = await fetch(url, {
2628
signal: controller.signal,
2729
...init,
2830
});
2931
clearTimeout(timeoutId);
3032

3133
if (response.status >= 400) {
34+
// gracefully handle HEAD method not allowed
35+
if (response.status === 405 && init?.method === 'HEAD') {
36+
return { response };
37+
}
38+
3239
throw ono({ status: response.status }, `HTTP ERROR ${response.status}`);
3340
}
3441

@@ -49,6 +56,7 @@ export const sendRequest = async ({
4956
return sendRequest({
5057
init,
5158
redirects,
59+
timeout,
5260
url: resolve(url.href, response.headers.location as string),
5361
});
5462
}

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@hey-api/json-schema-ref-parser",
3-
"version": "0.0.2",
3+
"version": "0.0.3",
44
"description": "Parse, Resolve, and Dereference JSON Schema $ref pointers",
55
"homepage": "https://heyapi.dev/",
66
"repository": {

0 commit comments

Comments
 (0)