Enhance health activity error handling: Implement detailed error responses in FalukantController for 'tooClose' scenarios, including retry timing. Update localization files for improved user feedback on health measures and errors. Refactor error handling in HealthView to display appropriate messages based on error responses.
This commit is contained in:
@@ -155,7 +155,16 @@ class FalukantController {
|
|||||||
this.advanceNobility = this._wrapWithUser((userId) => this.service.advanceNobility(userId));
|
this.advanceNobility = this._wrapWithUser((userId) => this.service.advanceNobility(userId));
|
||||||
|
|
||||||
this.getHealth = this._wrapWithUser((userId) => this.service.getHealth(userId));
|
this.getHealth = this._wrapWithUser((userId) => this.service.getHealth(userId));
|
||||||
this.healthActivity = this._wrapWithUser((userId, req) => this.service.healthActivity(userId, req.body.measureTr));
|
this.healthActivity = this._wrapWithUser(async (userId, req) => {
|
||||||
|
try {
|
||||||
|
return await this.service.healthActivity(userId, req.body.measureTr);
|
||||||
|
} catch (e) {
|
||||||
|
if (e && e.name === 'PreconditionError' && e.message === 'tooClose') {
|
||||||
|
throw { status: 412, message: 'tooClose', retryAt: e.meta?.retryAt };
|
||||||
|
}
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
this.getPoliticsOverview = this._wrapWithUser((userId) => this.service.getPoliticsOverview(userId));
|
this.getPoliticsOverview = this._wrapWithUser((userId) => this.service.getPoliticsOverview(userId));
|
||||||
this.getOpenPolitics = this._wrapWithUser((userId) => this.service.getOpenPolitics(userId));
|
this.getOpenPolitics = this._wrapWithUser((userId) => this.service.getOpenPolitics(userId));
|
||||||
|
|||||||
@@ -3662,7 +3662,11 @@ class FalukantService extends BaseService {
|
|||||||
limit: 1
|
limit: 1
|
||||||
});
|
});
|
||||||
if (lastHealthActivity) {
|
if (lastHealthActivity) {
|
||||||
throw new Error('too close');
|
// Berechne, wann die nächste Maßnahme möglich ist (24 Stunden nach der letzten)
|
||||||
|
const retryAt = new Date(lastHealthActivity.createdAt.getTime() + 24 * 60 * 60 * 1000);
|
||||||
|
const err = new PreconditionError('tooClose');
|
||||||
|
err.meta = { retryAt: retryAt.toISOString() };
|
||||||
|
throw err;
|
||||||
}
|
}
|
||||||
const activityObject = FalukantService.HEALTH_ACTIVITIES.find((a) => a.tr === activity);
|
const activityObject = FalukantService.HEALTH_ACTIVITIES.find((a) => a.tr === activity);
|
||||||
if (!activityObject) {
|
if (!activityObject) {
|
||||||
|
|||||||
@@ -895,7 +895,12 @@
|
|||||||
"drunkOfLife": "Trunk des Lebens",
|
"drunkOfLife": "Trunk des Lebens",
|
||||||
"barber": "Barbier"
|
"barber": "Barbier"
|
||||||
},
|
},
|
||||||
"choose": "Bitte auswählen"
|
"choose": "Bitte auswählen",
|
||||||
|
"errors": {
|
||||||
|
"tooClose": "Du kannst nicht so oft Maßnahmen durchführen.",
|
||||||
|
"generic": "Ein Fehler ist aufgetreten."
|
||||||
|
},
|
||||||
|
"nextMeasureAt": "Nächste Maßnahme ab"
|
||||||
},
|
},
|
||||||
"politics": {
|
"politics": {
|
||||||
"title": "Politik",
|
"title": "Politik",
|
||||||
|
|||||||
@@ -197,7 +197,32 @@
|
|||||||
},
|
},
|
||||||
"nobility": {
|
"nobility": {
|
||||||
"cooldown": "You can only advance again on {date}."
|
"cooldown": "You can only advance again on {date}."
|
||||||
},
|
},
|
||||||
|
"healthview": {
|
||||||
|
"title": "Health",
|
||||||
|
"age": "Age",
|
||||||
|
"status": "Health Status",
|
||||||
|
"measuresTaken": "Measures Taken",
|
||||||
|
"measure": "Measure",
|
||||||
|
"date": "Date",
|
||||||
|
"cost": "Cost",
|
||||||
|
"success": "Success",
|
||||||
|
"selectMeasure": "Select Measure",
|
||||||
|
"perform": "Perform",
|
||||||
|
"measures": {
|
||||||
|
"pill": "Pill",
|
||||||
|
"doctor": "Doctor Visit",
|
||||||
|
"witch": "Witch",
|
||||||
|
"drunkOfLife": "Elixir of Life",
|
||||||
|
"barber": "Barber"
|
||||||
|
},
|
||||||
|
"choose": "Please select",
|
||||||
|
"errors": {
|
||||||
|
"tooClose": "You cannot perform measures so often.",
|
||||||
|
"generic": "An error occurred."
|
||||||
|
},
|
||||||
|
"nextMeasureAt": "Next measure from"
|
||||||
|
},
|
||||||
"branchProduction": {
|
"branchProduction": {
|
||||||
"storageAvailable": "Free storage"
|
"storageAvailable": "Free storage"
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -142,9 +142,23 @@ export default {
|
|||||||
this.selectedTr = '';
|
this.selectedTr = '';
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error('Error performing measure', err);
|
console.error('Error performing measure', err);
|
||||||
const title = this.$t('falukant.healthview.title');
|
if (err?.response?.status === 412) {
|
||||||
const remoteMsg = err?.response?.data?.error || err?.message || String(err);
|
const retryAtIso = err.response?.data?.retryAt;
|
||||||
this.$root.$refs.messageDialog?.open(remoteMsg, title);
|
const code = err.response?.data?.error || err.response?.data?.message;
|
||||||
|
if (retryAtIso) {
|
||||||
|
const retryStr = new Date(retryAtIso).toLocaleString(navigator.language, {
|
||||||
|
year: 'numeric', month: '2-digit', day: '2-digit',
|
||||||
|
hour: '2-digit', minute: '2-digit'
|
||||||
|
});
|
||||||
|
const baseMsg = this.$t(`falukant.healthview.errors.${code}`);
|
||||||
|
this.$root.$refs.errorDialog?.open(`${baseMsg} — ${this.$t('falukant.healthview.nextMeasureAt')}: ${retryStr}`);
|
||||||
|
} else {
|
||||||
|
this.$root.$refs.errorDialog?.open(this.$t(`falukant.healthview.errors.${code}`));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
const code = err?.response?.data?.error || err?.message || 'generic';
|
||||||
|
this.$root.$refs.errorDialog?.open(this.$t(`falukant.healthview.errors.${code}`) || this.$t('falukant.healthview.errors.generic'));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
handleDaemonMessage(evt) {
|
handleDaemonMessage(evt) {
|
||||||
|
|||||||
Reference in New Issue
Block a user