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:
Torsten Schulz (local)
2026-01-28 13:34:42 +01:00
parent 08b6437a1e
commit d4fb2a8ccc
5 changed files with 64 additions and 7 deletions

View File

@@ -155,7 +155,16 @@ class FalukantController {
this.advanceNobility = this._wrapWithUser((userId) => this.service.advanceNobility(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.getOpenPolitics = this._wrapWithUser((userId) => this.service.getOpenPolitics(userId));

View File

@@ -3662,7 +3662,11 @@ class FalukantService extends BaseService {
limit: 1
});
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);
if (!activityObject) {