From a52b9e3052715634cd83c1c62def8edfe12f71fb Mon Sep 17 00:00:00 2001 From: Guus Ekkelenkamp Date: Tue, 2 Jun 2026 14:04:47 +0200 Subject: [PATCH] fix(ui): surface the real booking error instead of "Boeken mislukt" MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Tauri's invoke rejects with the Rust error STRING (e.g. the Simplicate API status + body), which isn't an Error instance — so the catch fell back to a generic "Boeken mislukt" and hid the actual reason a booking failed. Now string errors are shown as-is (and logged), with the generic message kept only for non-string, non-Error throws. Co-Authored-By: Claude Opus 4.8 (1M context) --- src/ui/hooks/useBooking.test.ts | 13 +++++++++++-- src/ui/hooks/useBooking.ts | 7 ++++++- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/ui/hooks/useBooking.test.ts b/src/ui/hooks/useBooking.test.ts index 70d474b..87af58e 100644 --- a/src/ui/hooks/useBooking.test.ts +++ b/src/ui/hooks/useBooking.test.ts @@ -190,8 +190,17 @@ describe('useBooking', () => { expect(result.current.errorMessage).toContain('API key') }) - it('book sets a default error message for non-Error throws', async () => { - bookExecute.mockRejectedValue('weird') + it('book surfaces a string error (e.g. the Simplicate API message) instead of a generic one', async () => { + bookExecute.mockRejectedValue('Simplicate API error: 400 — invalid type_id') + const { result } = renderHook(() => useBooking({ projectId: 'p1' })) + await act(async () => { + await result.current.book() + }) + expect(result.current.errorMessage).toBe('Simplicate API error: 400 — invalid type_id') + }) + + it('book falls back to a generic message for non-string, non-Error throws', async () => { + bookExecute.mockRejectedValue({ weird: true }) const { result } = renderHook(() => useBooking({ projectId: 'p1' })) await act(async () => { await result.current.book() diff --git a/src/ui/hooks/useBooking.ts b/src/ui/hooks/useBooking.ts index 014ffe2..337313a 100644 --- a/src/ui/hooks/useBooking.ts +++ b/src/ui/hooks/useBooking.ts @@ -130,7 +130,12 @@ export function useBooking(initial: Partial = {}) { setStatus('success') } catch (err) { setStatus('error') - setErrorMessage(err instanceof Error ? err.message : 'Boeken mislukt') + // Tauri's invoke rejects with the Rust error STRING (e.g. the Simplicate + // API status + body), not an Error — surface it instead of hiding the real + // reason behind a generic message. + console.error('[useBooking] booking failed:', err) + const msg = err instanceof Error ? err.message : typeof err === 'string' && err.trim() ? err : 'Boeken mislukt' + setErrorMessage(msg) } }