Skip to content

Commit c64106d

Browse files
committed
chore(tutorial): fix handle errors
1 parent de1fe6f commit c64106d

File tree

3 files changed

+28
-10
lines changed

3 files changed

+28
-10
lines changed

app/components/domain/TutorialAssetInput/index.tsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,15 @@ function TutorialAssetInput<const NAME>(props: Props<NAME>) {
106106
&& result.data.createTutorialAsset.result
107107
) {
108108
onChange(result.data.createTutorialAsset.result.id, name);
109+
} else {
110+
// eslint-disable-next-line no-underscore-dangle
111+
const errorMessage = result.data
112+
?.createTutorialAsset?.__typename === 'OperationInfo'
113+
? result.data.createTutorialAsset.messages
114+
: result.data?.createTutorialAsset?.errors?.[0]?.message
115+
|| 'Failed to upload file. Please try again.';
116+
// eslint-disable-next-line no-console
117+
console.error(errorMessage);
109118
}
110119
}
111120
}, [createTutorialAsset, tutorialId, onChange, name]);

app/components/domain/TutorialAssetPreview/index.tsx

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -67,22 +67,30 @@ function TutorialAssetPreview(props: Props) {
6767

6868
useEffect(() => {
6969
async function fetchGeoJson() {
70-
if (isNotDefined(previewResponse)
70+
if (
71+
isNotDefined(previewResponse)
7172
|| previewResponse.tutorialAsset.mimetype !== Geojson
7273
) {
7374
return;
7475
}
7576

76-
const geoJsonResponse = await fetch(
77-
previewResponse.tutorialAsset.file.url,
78-
);
79-
80-
const rawGeoJson = await geoJsonResponse.json();
81-
82-
// TODO: validate
83-
setGeoJson(rawGeoJson);
77+
fetch(previewResponse.tutorialAsset.file.url)
78+
.then((geoJsonResponse) => {
79+
if (!geoJsonResponse.ok) {
80+
throw new Error('Failed to fetch GeoJSON file.');
81+
}
82+
return geoJsonResponse.json();
83+
})
84+
.then((rawGeoJson) => {
85+
// TODO: validate
86+
setGeoJson(rawGeoJson);
87+
})
88+
.catch((error) => {
89+
// eslint-disable-next-line no-console
90+
console.error('Error fetching GeoJSON:', error);
91+
setGeoJson(undefined);
92+
});
8493
}
85-
8694
fetchGeoJson();
8795
}, [previewResponse, Geojson]);
8896

app/views/EditTutorial/index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -622,6 +622,7 @@ function NewTutorial(props: Props) {
622622
clientId: ulid(),
623623
reference: feature.properties.reference,
624624
projectTypeSpecifics: {
625+
// FIXME: Why objectGeometry is string?
625626
validate: {
626627
objectGeometry: JSON.stringify(feature.geometry, null, 4),
627628
} satisfies ValidatePropertyInputFields,

0 commit comments

Comments
 (0)