Skip to content

Commit 8547006

Browse files
committed
add url to fetch error
1 parent 7f917c9 commit 8547006

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

index.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,15 @@ import fetchEnhanced from "fetch-enhanced";
1111
const fetch = fetchEnhanced(undiciFetch, {undici: true});
1212
const clone = cloner();
1313

14+
async function doFetch(url, opts) {
15+
try {
16+
return await fetch(url, opts);
17+
} catch (err) {
18+
err.message = `${err.message} (${url})`;
19+
throw err;
20+
}
21+
}
22+
1423
async function extract(res) {
1524
const styleUrls = [];
1625
const styleTags = [];
@@ -106,7 +115,7 @@ async function extensionCss({crx, contentScriptsOnly, strict}) {
106115
url += `&x=id%3D${crx}`;
107116
url += `%26uc`;
108117

109-
const res = await fetch(url);
118+
const res = await doFetch(url);
110119
validateStatus(res, url, strict);
111120

112121
const crxBuffer = arrayBufferToBufferCycle(await res.arrayBuffer());
@@ -176,7 +185,7 @@ export default async function fetchCss(sources) { // eslint-disable-line import/
176185
const sourceResponses = await Promise.all(sources.map(source => {
177186
if (!source.url) return null;
178187
const {pathname} = new URL(source.url);
179-
return pathname.endsWith(".css") || pathname.endsWith(".js") ? null : fetch(source.url, source.fetchOpts);
188+
return pathname.endsWith(".css") || pathname.endsWith(".js") ? null : doFetch(source.url, source.fetchOpts);
180189
}));
181190

182191
for (const [index, res] of Object.entries(sourceResponses)) {
@@ -193,7 +202,7 @@ export default async function fetchCss(sources) { // eslint-disable-line import/
193202

194203
const fetchResponses = await Promise.all(sources.map(source => {
195204
if (!source.url) return null;
196-
return Promise.all(source.urls.map(url => fetch(url).then(res => res.text())));
205+
return Promise.all(source.urls.map(url => doFetch(url).then(res => res.text())));
197206
}));
198207

199208
for (const [index, responses] of Object.entries(fetchResponses)) {

0 commit comments

Comments
 (0)