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.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));
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user