From 1e110b8cd1ba00d1b8e8a9b7c48e18bd790a895b Mon Sep 17 00:00:00 2001 From: jeremydolle Date: Wed, 9 Oct 2024 15:30:04 +0200 Subject: [PATCH] Refactor image and icon loading error handling --- .../src/components/atoms/AssetByVariant/AssetByVariant.tsx | 5 ++++- .../src/components/atoms/IconByVariant/IconByVariant.tsx | 6 ++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/template/src/components/atoms/AssetByVariant/AssetByVariant.tsx b/template/src/components/atoms/AssetByVariant/AssetByVariant.tsx index 33cb140d..36ac1cbb 100644 --- a/template/src/components/atoms/AssetByVariant/AssetByVariant.tsx +++ b/template/src/components/atoms/AssetByVariant/AssetByVariant.tsx @@ -36,7 +36,10 @@ function AssetByVariant({ path, extension = 'png', ...props }: Props) { setImage(fetchedModule); } catch (error) { // eslint-disable-next-line no-console - console.error(`Couldn't load the image: ${path}.${extension} for the variant ${variant}, Fallback to default`, error); + console.error( + `Couldn't load the image: ${path}.${extension} for the variant ${variant}, Fallback to default`, + error, + ); setImage(defaultSource); } } catch (error) { diff --git a/template/src/components/atoms/IconByVariant/IconByVariant.tsx b/template/src/components/atoms/IconByVariant/IconByVariant.tsx index e09ec9d8..062885f7 100644 --- a/template/src/components/atoms/IconByVariant/IconByVariant.tsx +++ b/template/src/components/atoms/IconByVariant/IconByVariant.tsx @@ -37,10 +37,12 @@ function IconByVariant({ path, ...props }: Props) { setIcon(fetchedModule.default); } catch (error) { // eslint-disable-next-line no-console - console.error(`Couldn't load the icon: ${path}.${EXTENSION} for the variant ${variant}, Fallback to default`, error); + console.error( + `Couldn't load the icon: ${path}.${EXTENSION} for the variant ${variant}, Fallback to default`, + error, + ); setIcon(defaultSource.default); } - } catch (error) { // eslint-disable-next-line no-console console.error(`Couldn't load the icon: ${path}.${EXTENSION}`, error);