Add error handling for nobility advancement in NobilityView: Implemented specific error messages for cooldown and unmet requirements, enhancing user feedback during advancement attempts.

This commit is contained in:
Torsten Schulz (local)
2026-02-09 12:03:59 +01:00
parent 8c40144734
commit c779be2897
3 changed files with 35 additions and 2 deletions

View File

@@ -738,7 +738,12 @@
"advance": { "advance": {
"confirm": "Aufsteigen beantragen" "confirm": "Aufsteigen beantragen"
}, },
"cooldown": "Du kannst frühestens wieder am {date} aufsteigen." "cooldown": "Du kannst frühestens wieder am {date} aufsteigen.",
"errors": {
"tooSoon": "Aufstieg zu früh.",
"unmet": "Folgende Voraussetzungen fehlen:",
"generic": "Der Aufstieg ist fehlgeschlagen."
}
}, },
"reputation": { "reputation": {
"title": "Reputation", "title": "Reputation",

View File

@@ -196,7 +196,12 @@
} }
}, },
"nobility": { "nobility": {
"cooldown": "You can only advance again on {date}." "cooldown": "You can only advance again on {date}.",
"errors": {
"tooSoon": "Advancement too soon.",
"unmet": "The following requirements are not met:",
"generic": "Advancement failed."
}
}, },
"branchProduction": { "branchProduction": {
"storageAvailable": "Free storage" "storageAvailable": "Free storage"

View File

@@ -124,6 +124,29 @@
await this.loadNobility(); await this.loadNobility();
} catch (err) { } catch (err) {
console.error('Error advancing nobility:', err); console.error('Error advancing nobility:', err);
const resp = err?.response;
if (resp?.status === 412) {
if (resp.data?.message === 'nobilityTooSoon') {
const retryAtIso = resp.data?.retryAt;
const retryStr = retryAtIso ? this.formatDate(retryAtIso) : '';
const msg = this.$t('falukant.nobility.errors.tooSoon');
this.$root.$refs.errorDialog?.open(retryStr ? `${msg}${this.$t('falukant.nobility.cooldown', { date: retryStr })}` : msg);
} else if (resp.data?.message === 'nobilityRequirements') {
const unmet = resp.data?.unmet || [];
const items = unmet.map(u => {
if (u.type === 'money') return this.$t('falukant.nobility.requirement.money', { amount: this.formatCost(u.required) });
if (u.type === 'cost') return this.$t('falukant.nobility.requirement.cost', { amount: this.formatCost(u.required) });
if (u.type === 'branches') return this.$t('falukant.nobility.requirement.branches', { amount: u.required });
return `${u.type}: ${u.required}`;
}).join('\n');
const base = this.$t('falukant.nobility.errors.unmet');
this.$root.$refs.errorDialog?.open(`${base}\n${items}`);
} else {
this.$root.$refs.errorDialog?.open('tr:falukant.nobility.errors.generic');
}
} else {
this.$root.$refs.errorDialog?.open('tr:falukant.nobility.errors.generic');
}
} finally { } finally {
this.isAdvancing = false; this.isAdvancing = false;
} }