Skip to content

Commit

Permalink
Image load timeout (#75)
Browse files Browse the repository at this point in the history
* fix(image): increased load timeout

* fix(images): improved error handling
  • Loading branch information
seth2810 authored Aug 15, 2024
1 parent 99d38dc commit ba3d898
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions src/utils/images/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,14 +185,11 @@ export async function fetchExternalImage(
fallbackImg?: string,
): Promise<ImageUpstream> {
return fetch(href, {
signal: AbortSignal.timeout(1_000),
signal: AbortSignal.timeout(5_000),
})
.then(async (res) => {
if (!res.ok) {
throw new ImageError(
res.status,
`Upstream image response failed: ${await res.text()}`,
);
throw new ImageError(res.status, `upstream image response failed`);
}

const content = await res.arrayBuffer();
Expand All @@ -206,13 +203,13 @@ export async function fetchExternalImage(
};
})
.catch((error) => {
// eslint-disable-next-line no-console
console.warn(`Unable to fetch external image "${href}":`, String(error));

if (fallbackImg) {
return fetchExternalImage(fallbackImg);
}

// eslint-disable-next-line no-console
console.warn(`Unable to fetch external image "${href}":`, error);

throw error;
});
}
Expand Down

0 comments on commit ba3d898

Please sign in to comment.