fix(errors): show a route's Swedish message even without a keyword match (#2086) (#2253)

* fix(errors): show a route's Swedish message even without a keyword match (#2086)

getErrorMessage passed a route's free-text `error` / `message` through
only if it contained one of ~30 keywords ("kunde inte", "saknas", ...).
"Inget skattekonto är registrerat hos Skatteverket." has none, so the
skattekonto sync replaced the one sentence that would have helped with
"Ett oväntat serverfel uppstod. Försök igen senare.", which is wrong
advice for a company without a skattekonto. 155 of the 631 message_sv
strings in structured-errors.ts failed the same keyword test.

A second way in: looksLikeUserFacingSwedish accepts a string that reads
as Swedish (å/ä/ö, a strong Swedish word, or two weak function words)
and shows no sign of a technical leak (stack frames, file:line, JS/Node
error vocabulary, Postgres/PostgREST/SQL fragments, JSON, URLs). The
keyword list stays as the first way in. English framework text still
falls through to the status/context fallback, and a registry-wide test
pins that every message_sv now passes.

Closes #2086

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VnConrmMCxJRQ5kfiPPWyy

* test(errors): pin the two call sites whose Swedish messages now pass through (#2086)

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VnConrmMCxJRQ5kfiPPWyy

---------

Co-authored-by: Jakob Wennberg <311770904+jakobwennberg-oss@users.noreply.github.com>
Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
Jakob Wennberg
2026-09-03 18:55:33 +02:00
committed by GitHub
co-authored by Claude Fable 5.1 Jakob Wennberg
parent 5070041028
commit c3b7e79af8
4 changed files with 180 additions and 11 deletions
@@ -97,13 +97,27 @@ describe('POST /api/bookkeeping/accruals/[id]/dissolve', () => {
expect(body.error.code).toBe('ACCRUAL_NOTHING_TO_DISSOLVE')
})
it('falls back to ACCRUAL_DISSOLVE_FAILED for untyped errors', async () => {
it('falls back to ACCRUAL_DISSOLVE_FAILED for untyped errors, carrying a Swedish reason as-is', async () => {
mockDissolveScheduleNow.mockRejectedValue(new Error('Ingen öppen räkenskapsperiod för 2026-01-01'))
const { status, body } = await parseJsonResponse<{
error: { code: string; details: { reason: string } }
}>(await dissolveRequest())
expect(status).toBe(400)
expect(body.error.code).toBe('ACCRUAL_DISSOLVE_FAILED')
// The engine's own Swedish sentence reaches the user (issue #2086); it
// used to be dropped for lacking a getErrorMessage keyword.
expect(body.error.details.reason).toBe('Ingen öppen räkenskapsperiod för 2026-01-01')
})
it('falls back to ACCRUAL_DISSOLVE_FAILED with the generic reason for untyped technical errors', async () => {
mockDissolveScheduleNow.mockRejectedValue(new Error('boom'))
const { status, body } = await parseJsonResponse<{
error: { code: string; details: { reason: string } }
}>(await dissolveRequest())
expect(status).toBe(400)
expect(body.error.code).toBe('ACCRUAL_DISSOLVE_FAILED')
expect(body.error.details.reason).toBe('Något gick fel. Försök igen.')