Refactor error handling in FalukantService and enhance user feedback in HealthView

- Changed error throwing in FalukantService to use PreconditionError for better clarity.
- Added translations for "too close" error in both German and English locales.
- Improved user feedback in HealthView by displaying error messages in a dialog upon measure execution failure.
This commit is contained in:
Torsten Schulz (local)
2025-12-23 12:20:37 +01:00
parent 820b5e8570
commit 5623f3af09
4 changed files with 20 additions and 2 deletions

View File

@@ -4180,7 +4180,7 @@ class FalukantService extends BaseService {
limit: 1 limit: 1
}); });
if (lastHealthActivity) { if (lastHealthActivity) {
throw new Error('too close'); throw new PreconditionError('tr:falukant.healthview.errors.tooClose');
} }
const activityObject = FalukantService.HEALTH_ACTIVITIES.find((a) => a.tr === activity); const activityObject = FalukantService.HEALTH_ACTIVITIES.find((a) => a.tr === activity);
if (!activityObject) { if (!activityObject) {

View File

@@ -918,6 +918,9 @@
"success": "Erfolg", "success": "Erfolg",
"selectMeasure": "Maßnahme", "selectMeasure": "Maßnahme",
"perform": "Durchführen", "perform": "Durchführen",
"errors": {
"tooClose": "Aktionen zu dicht hintereinander (maximal 1× pro 24 Stunden)."
},
"measures": { "measures": {
"pill": "Tablette", "pill": "Tablette",
"doctor": "Arztbesuch", "doctor": "Arztbesuch",

View File

@@ -100,6 +100,12 @@
"bad": "Bad", "bad": "Bad",
"very_bad": "Very bad" "very_bad": "Very bad"
}, },
"healthview": {
"title": "Health",
"errors": {
"tooClose": "Actions too close together (max once per 24 hours)."
}
},
"moneyHistory": { "moneyHistory": {
"title": "Money history", "title": "Money history",
"filter": "Filter", "filter": "Filter",

View File

@@ -129,13 +129,22 @@ export default {
async performMeasure() { async performMeasure() {
if (!this.selectedMeasure) return; if (!this.selectedMeasure) return;
try { try {
await apiClient.post('/api/falukant/health', { const { data } = await apiClient.post('/api/falukant/health', {
measureTr: this.selectedTr measureTr: this.selectedTr
}); });
// Feedback via global message dialog
const title = this.$t('falukant.healthview.title');
const body = data?.delta != null
? `${this.$t(`falukant.healthview.measures.${this.selectedTr}`)}: ${data.delta > 0 ? '+' : ''}${data.delta}`
: this.$t('message.success');
this.$root.$refs.messageDialog?.open(body, title);
await this.loadHealthData(); await this.loadHealthData();
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');
const remoteMsg = err?.response?.data?.error || err?.message || String(err);
this.$root.$refs.messageDialog?.open(remoteMsg, title);
} }
}, },
handleDaemonMessage(evt) { handleDaemonMessage(evt) {