Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions src/ui/hooks/useBooking.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
7 changes: 6 additions & 1 deletion src/ui/hooks/useBooking.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,12 @@ export function useBooking(initial: Partial<HourEntry> = {}) {
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)
}
}

Expand Down
Loading