Skip to content

Commit 41e6ee3

Browse files
authored
Merge pull request #80 from cividi/feat/snapshot-upload-backend-errors
Feat: Snapshot upload errors
2 parents d77a65a + f35b1bd commit 41e6ee3

File tree

1 file changed

+37
-5
lines changed

1 file changed

+37
-5
lines changed

vue/src/components/SnapshotEdit.vue

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@
2222
"savingInfo": "Speichere Angaben",
2323
"sendingFile": "Sende Datei",
2424
"done": "Fertig"
25+
},
26+
"error": {
27+
"unspecified": "Etwas ist schiefgelaufen. Stellen Sie sicher, dass Sie eingeloggt sind und alle Daten korrekt eingegeben haben."
2528
}
2629
},
2730
"fr": {
@@ -40,7 +43,15 @@
4043
"savefile": "Sende Datei",
4144
"predecessor": "version prédécesseuse",
4245
"municipalityMandatory": "Veuillez sélectionner une municipalité",
43-
"noMatches": "Aucun résultat"
46+
"noMatches": "Aucun résultat",
47+
"status": {
48+
"savingInfo": "Enregistrer les détails",
49+
"sendingFile": "Envoyer le fichier",
50+
"done": "Prêt"
51+
},
52+
"error": {
53+
"unspecified": "Quelque chose a mal tourné. Assurez-vous que vous êtes connecté et que vous avez saisi toutes les données correctement."
54+
}
4455
}
4556
}
4657
</i18n>
@@ -50,6 +61,14 @@
5061
<v-card id="snapshotedit" light width="400" class="pa-4">
5162
<h3 v-if="isNew">{{ $t('newsnapshot') }}</h3>
5263
<h3 v-else>{{ $t('editsnapshot') }}</h3>
64+
<v-alert
65+
v-for="(error, errorIndex) in errors"
66+
:key="errorIndex"
67+
type="error"
68+
class="mt-2 mb-0"
69+
>
70+
{{ $t(`error.${error.code || 'unspecified'}`) }}
71+
</v-alert>
5372
<v-form
5473
v-if="!saving"
5574
class="pt-4"
@@ -83,7 +102,9 @@
83102
required
84103
@update:search-input="queryAndSetMunicipalities"
85104
:rules="[
86-
(municipality) => municipality && municipality.bfsNumber || $t('municipalityMandatory')
105+
(municipality) =>
106+
!!(municipality && municipality.bfsNumber) ||
107+
$t('municipalityMandatory')
87108
]"
88109
:hide-no-data="!municipalities.length"
89110
>
@@ -99,7 +120,7 @@
99120
:label="$t('file')"
100121
truncate-length="20"
101122
:rules="[
102-
file => !!snapshot.datafile ||
123+
file => !!datafile ||
103124
!!(file && file.name && file.type === 'application/json') ||
104125
$t('mandatory')
105126
]"
@@ -166,7 +187,9 @@ export default {
166187
municipality: this.municipality,
167188
file: undefined
168189
},
169-
wshash: btoa(`WorkspaceNode:${this.$route.params.wshash}`)
190+
wshash: btoa(`WorkspaceNode:${this.$route.params.wshash}`),
191+
selectedMunicipality: undefined,
192+
errors: []
170193
};
171194
},
172195
@@ -225,6 +248,7 @@ export default {
225248
return;
226249
}
227250
251+
this.errors = [];
228252
this.saving = true;
229253
this.status = this.$t('status.savingInfo');
230254
@@ -264,7 +288,12 @@ export default {
264288
this.$emit('saved', { isNew: this.isNew, snapshot: data.snapshotmutation.snapshot });
265289
this.status = this.$t('status.done');
266290
} catch (error) {
267-
// TODO: show error
291+
// apollo's errors are a bit strange
292+
if (error.graphQLErrors && error.networkError) {
293+
this.showErrors(...error.graphQLErrors, ...error.networkError.result.errors);
294+
} else {
295+
this.showErrors(error);
296+
}
268297
this.progress = 0;
269298
this.selected.file = undefined;
270299
} finally {
@@ -297,6 +326,9 @@ export default {
297326
const municipalities = await this.queryMunicipalities(searchInput);
298327
this.municipalities = municipalities;
299328
}
329+
},
330+
showErrors(...errors) {
331+
this.errors = [...this.errors, ...errors];
300332
}
301333
}
302334
};

0 commit comments

Comments
 (0)