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:
@@ -124,6 +124,29 @@
|
||||
await this.loadNobility();
|
||||
} catch (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 {
|
||||
this.isAdvancing = false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user