Skip to content

Commit 408898c

Browse files
committed
Merge remote-tracking branch 'origin/master'
2 parents ec29460 + 080b08a commit 408898c

File tree

3 files changed

+31
-26
lines changed

3 files changed

+31
-26
lines changed

package-lock.json

Lines changed: 2 additions & 2 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 & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ipfs-race",
3-
"version": "0.1.3",
3+
"version": "0.1.4",
44
"description": "Resolve an IPFS path using multiple gateways and methods to get data the fastest.",
55
"main": "dist/index.js",
66
"scripts": {

src/resolve.ts

Lines changed: 28 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -151,29 +151,34 @@ async function resolve(uri: string, options?: ResolveOptions): Promise<ResolveOu
151151
// create a promise to each gateway
152152
const promises = gateways.map(async (gatewayUrl, i): Promise<ResolveOutput> => {
153153

154-
// create an abort controller to stop the fetch requests when the first one is resolved.
155-
const controller = new AbortController();
156-
const signal = controller.signal;
157-
abortControllers[i] = controller;
158-
159-
const urlResolvedFrom = `${gatewayUrl}${gatewaySuffix}`;
160-
const response = await _options.fetchOverride(urlResolvedFrom, {
161-
method: "get",
162-
signal,
163-
} as RequestInit);
164-
165-
// remove the abort controller for the completed response
166-
abortControllers[i] = undefined;
167-
168-
// check the response because a lot of gateways will do redirects and other checks which will not be compatible
169-
// with this library
170-
if(response.status >= 300 || response.status < 200) {
171-
throw new Error(`Url (${urlResolvedFrom}) did not return a 2xx response`);
172-
}
173-
174-
return {
175-
response,
176-
urlResolvedFrom
154+
try {
155+
// create an abort controller to stop the fetch requests when the first one is resolved.
156+
const controller = new AbortController();
157+
const signal = controller.signal;
158+
abortControllers[i] = controller;
159+
160+
const urlResolvedFrom = `${gatewayUrl}${gatewaySuffix}`;
161+
const response = await _options.fetchOverride(urlResolvedFrom, {
162+
method: "get",
163+
signal,
164+
} as RequestInit);
165+
166+
// remove the abort controller for the completed response
167+
abortControllers[i] = undefined;
168+
169+
// check the response because a lot of gateways will do redirects and other checks which will not be compatible
170+
// with this library
171+
if(response.status >= 300 || response.status < 200) {
172+
throw new Error(`Url (${urlResolvedFrom}) did not return a 2xx response`);
173+
}
174+
175+
return {
176+
response,
177+
urlResolvedFrom
178+
}
179+
} catch (err) {
180+
console.error(gatewayUrl, err);
181+
throw err;
177182
}
178183
})
179184

0 commit comments

Comments
 (0)