Components: ImageEditor: add error handler

This commit is contained in:
Viktor Fomin 2023-05-02 14:22:28 +03:00
parent 93fd498284
commit df4c90d838

View File

@ -76,37 +76,45 @@ const Dropzone = ({ t, setUploadedFile, isDisabled }) => {
timer.current = setTimeout(() => {
setLoadingFile(true);
}, 50);
const imageBitMap = await createImageBitmap(file);
try {
const imageBitMap = await createImageBitmap(file);
const width = imageBitMap.width;
const height = imageBitMap.height;
const canvas = resizeImage.resize2Canvas(imageBitMap, width, height);
const width = imageBitMap.width;
const height = imageBitMap.height;
const canvas = resizeImage.resize2Canvas(imageBitMap, width, height);
resizeRecursiveAsync(
{ width, height },
canvas,
file.size > ONE_MEGABYTE ? COMPRESSION_RATIO : NO_COMPRESSION_RATIO
)
.then((file) => {
if (mount.current) {
setUploadedFile(file);
}
})
.catch((error) => {
if (
error instanceof Error &&
error.message === "recursion depth exceeded"
) {
toastr.error(t("Common:SizeImageLarge"));
}
console.error(error);
})
.finally(() => {
timer.current && clearTimeout(timer.current);
if (mount.current) {
setLoadingFile(false);
}
});
resizeRecursiveAsync(
{ width, height },
canvas,
file.size > ONE_MEGABYTE ? COMPRESSION_RATIO : NO_COMPRESSION_RATIO
)
.then((file) => {
if (mount.current) {
setUploadedFile(file);
}
})
.catch((error) => {
if (
error instanceof Error &&
error.message === "recursion depth exceeded"
) {
toastr.error(t("Common:SizeImageLarge"));
}
console.error(error);
})
.finally(() => {
timer.current && clearTimeout(timer.current);
if (mount.current) {
setLoadingFile(false);
}
});
} catch (error) {
toastr.error(error);
timer.current && clearTimeout(timer.current);
if (mount.current) {
setLoadingFile(false);
}
}
};
const { getRootProps, getInputProps } = useDropzone({