(fix) show error message dialogue even though it is untranslatable

also prevents closing due to timeout when show() is called just after hide()
This commit is contained in:
Valentyne Stigloher 2024-03-07 15:08:31 +01:00
parent 4678c325f8
commit 52f305cbf5
3 changed files with 13 additions and 3 deletions

View File

@ -61,6 +61,7 @@ export default Vue.extend({
return {
shown: false,
shownFull: false,
hideTimeout: undefined as ReturnType<typeof setTimeout> | undefined,
choice: false,
icon: undefined as string | undefined,
header: undefined as string | undefined,
@ -102,6 +103,7 @@ export default Vue.extend({
resolve: (value: string | string[] | undefined) => void,
reject: () => void,
) {
clearTimeout(this.hideTimeout);
this.choice = choice;
if (typeof message === 'string') {
message = { message };
@ -134,7 +136,7 @@ export default Vue.extend({
},
hide() {
this.shownFull = false;
setTimeout(() => {
this.hideTimeout = setTimeout(() => {
this.shown = false;
this.choice = false;
this.icon = undefined;

View File

@ -15,7 +15,7 @@
</h1>
<template v-else>
<Avatar v-if="link.avatar" :user="link.avatar" dsize="1.6rem" />
<Icon v-else :v="link.icon" size="1.6" />
<Icon v-else :v="link.icon" :size="1.6" />
<br>
<span class="text-nowrap"><Spelling :text="link.text" /></span>
</template>

View File

@ -153,7 +153,15 @@ export default dark.extend({
this.$axios.$post(url, data, { ...options, timeout })
.then((data) => resolve(data))
.catch(async (error) => {
await this.$alert(this.$t(error.response?.data?.error || 'error.generic'), 'danger');
let errorMessage = this.$t('error.generic');
if (typeof error.response?.data?.error === 'string') {
errorMessage = this.$t(error.response?.data?.error);
// in case no translatable key was provided
if (errorMessage === undefined) {
errorMessage = error.response?.data?.error;
}
}
await this.$alert(errorMessage, 'danger');
reject(new Error(`POST to ${url} failed: ${error.response?.data?.error || 'unknown error'}`));
});
});