Skip to content

Commit

Permalink
Include module url in the error message when fetch() fails before rea…
Browse files Browse the repository at this point in the history
…ching the server

One noraty case is when Googlebot crawls the pages: fetch() rejects with the plain "Failed to fetch" error. Another case would be when fetch fails due to CORS or lack of internet.
  • Loading branch information
klesun authored Jul 28, 2024
1 parent 4dc28a7 commit 310e6dc
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/WorkerManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,12 @@ function bufferToHex (buffer) {

function tryFetchModuleSrcWithExt(fullUrl) {
return fetch(fullUrl)
.catch(error => {
if (error instanceof Error) {
error.message += ' ' + fullUrl;
}
throw error;
})
.then(rs => {
if (rs.status === 200) {
return rs.text().then(tsCode => ({fullUrl, tsCode}));
Expand Down

0 comments on commit 310e6dc

Please sign in to comment.