fix(loyalty-terminal): localise cooldown toast (was raw English)
Some checks failed
CI / ruff (push) Successful in 17s
CI / docs (push) Has been cancelled
CI / deploy (push) Has been cancelled
CI / validate (push) Has been cancelled
CI / dependency-scanning (push) Has been cancelled
CI / pytest (push) Has been cancelled

When earn-points or add-stamp was rejected by the new cooldown
enforcement, the terminal showed the raw English error message from
the backend in the toast, even on FR / DE / LB locales:
  "Transaction failed: Please wait 15 minutes between point-earning..."

Two-part fix:

1. static/shared/js/api-client.js — when raising apiError on non-OK
   responses, also propagate the `details` payload from the response
   body (alongside the existing errorCode). Without this the catch
   sites had no structured access to e.g. cooldown_minutes.

2. loyalty-terminal.js — in the catch around the transaction dispatch,
   when error.errorCode is POINTS_COOLDOWN or STAMP_COOLDOWN, render a
   new localised key loyalty.store.terminal.cooldown_wait_minutes with
   {minutes} interpolated from error.details.cooldown_minutes (with a
   fallback to this.program.cooldown_minutes). Toast type switches to
   'warning' since the rejection is soft (try again later) rather than
   a hard failure. Other errors keep the existing 'transaction_failed'
   path so nothing else regresses.

Added the new key in en / fr / de / lb under the existing
loyalty.store.terminal.* namespace (sibling of the existing
cooldown_active label).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-05-23 23:16:32 +02:00
parent f9a15deed7
commit aa8ca59493
2 changed files with 12 additions and 1 deletions

View File

@@ -275,7 +275,14 @@ function storeLoyaltyTerminal() {
await this.loadRecentTransactions();
} catch (error) {
Utils.showToast(I18n.t('loyalty.store.terminal.transaction_failed', {message: error.message}), 'error');
// Localise well-known errors by error_code instead of
// showing the raw English message from the API.
if (error.errorCode === 'POINTS_COOLDOWN' || error.errorCode === 'STAMP_COOLDOWN') {
const minutes = error.details?.cooldown_minutes ?? this.program?.cooldown_minutes ?? '';
Utils.showToast(I18n.t('loyalty.store.terminal.cooldown_wait_minutes', {minutes}), 'warning');
} else {
Utils.showToast(I18n.t('loyalty.store.terminal.transaction_failed', {message: error.message}), 'error');
}
loyaltyTerminalLog.error('Transaction failed:', error);
} finally {
this.processing = false;