Skip to content

Commit 6c68045

Browse files
committed
show image not found error message
1 parent e00cfa4 commit 6c68045

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

client/src/Annotation/index.jsx

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -163,10 +163,18 @@ export default () => {
163163
}
164164
const fetchImages = async (imageUrls, lastOpenedImage) => {
165165
try {
166-
const fetchPromises = imageUrls.map(url =>
167-
fetch(url.src).then(response => response.blob())
168-
.then(blob => ({ ...url, src: URL.createObjectURL(blob) }))
169-
);
166+
const fetchPromises = imageUrls.map(async url => {
167+
const response = await fetch(url.src);
168+
if (!response.ok) {
169+
if (response.status === 404) {
170+
const errorMSG = `${t("error.image_not_found")}: ${url.src}`;
171+
throw new Error(errorMSG);
172+
}
173+
}
174+
const blob = await response.blob();
175+
return { ...url, src: URL.createObjectURL(blob) };
176+
});
177+
170178
const images = await Promise.all(fetchPromises);
171179
const imageURLSrcs = imageUrls.map(url => decodeURIComponent(url.src.split('/').pop()));
172180
let image_annotations = await getImagesAnnotation({image_names: imageURLSrcs});
@@ -195,6 +203,7 @@ export default () => {
195203
setIsLoading(false)
196204
} catch (error) {
197205
showSnackbar(error.message, 'error');
206+
setIsLoading(false);
198207
} finally {
199208
setLoading(false);
200209
}

0 commit comments

Comments
 (0)