Skip to content

Commit

Permalink
fix: on 403 retry fetching image (#891)
Browse files Browse the repository at this point in the history
* fix: on 403 retry fetching image

* fix: clear interval on status other than 403

* fix: lower wait time
  • Loading branch information
IanKrieger authored Sep 20, 2023
1 parent 09302cf commit 6034f53
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
21 changes: 17 additions & 4 deletions src/components/Assets/hooks/useGetImagePreviewUrl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,26 @@ export function useGetImagePreviewUrl(props: { url: string }) {
const [loading, setLoading] = useState(false);
const [error, setError] = useState<string>();

const fetchImageResource = useMemo(async () => {
const fetchImageResource: Promise<ArrayBuffer> = useMemo(async () => {
const result = await fetchResource(props.url);
if (!result.ok) {
throw new Error("Unable to fetch image");
if (result.ok) {
return await result.arrayBuffer();
}

return await result.arrayBuffer();
return await new Promise((resolve, reject) => {
const intrvl = setInterval(async () => {
const result = await fetchResource(props.url);
if (result.status === 200) {
clearInterval(intrvl);
resolve(await result.arrayBuffer());
}

if (result.status !== 403) {
clearInterval(intrvl);
reject(new Error("Unable to fetch image"));
}
}, 2000);
});
}, [props.url]);

useEffect(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export function EngagementsOverview({
const options = prepareChart(metrics, processedData);

return (
<Box display="flex" flexDirection="row">
<Box display="flex" flexDirection="row" gap="5px">
<MetricFilter
processedStats={processedStats}
metrics={metrics}
Expand Down

0 comments on commit 6034f53

Please sign in to comment.