diff options
| author | nsfisis <nsfisis@gmail.com> | 2025-12-31 19:39:47 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2025-12-31 19:39:47 +0900 |
| commit | 73ee02825f57d971f6f660fc5277d4aa268702ff (patch) | |
| tree | 2e7ed277375674982f87d156dc6012a683f5fe2d /src | |
| parent | f211ebcfac0a21e264b67c1226509896a11ed5ca (diff) | |
| download | kioku-73ee02825f57d971f6f660fc5277d4aa268702ff.tar.gz kioku-73ee02825f57d971f6f660fc5277d4aa268702ff.tar.zst kioku-73ee02825f57d971f6f660fc5277d4aa268702ff.zip | |
fix(client): parse nested error object in API responses
Server returns `{ error: { message, code } }` but client expected
`{ error: string, code }`, causing "[object Object]" to display
on login failure.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Diffstat (limited to 'src')
| -rw-r--r-- | src/client/api/client.test.ts | 6 | ||||
| -rw-r--r-- | src/client/api/client.ts | 5 | ||||
| -rw-r--r-- | src/client/api/types.ts | 6 |
3 files changed, 11 insertions, 6 deletions
diff --git a/src/client/api/client.test.ts b/src/client/api/client.test.ts index 16deb28..5489547 100644 --- a/src/client/api/client.test.ts +++ b/src/client/api/client.test.ts @@ -85,8 +85,10 @@ describe("ApiClient", () => { { status: 401, body: { - error: "Invalid username or password", - code: "INVALID_CREDENTIALS", + error: { + message: "Invalid username or password", + code: "INVALID_CREDENTIALS", + }, }, }, ]); diff --git a/src/client/api/client.ts b/src/client/api/client.ts index 36a7431..7741942 100644 --- a/src/client/api/client.ts +++ b/src/client/api/client.ts @@ -66,9 +66,10 @@ export class ApiClient { if (!response.ok) { const errorBody = (await response.json().catch(() => ({}))) as ApiError; throw new ApiClientError( - errorBody.error || `Request failed with status ${response.status}`, + errorBody.error?.message || + `Request failed with status ${response.status}`, response.status, - errorBody.code, + errorBody.error?.code, ); } diff --git a/src/client/api/types.ts b/src/client/api/types.ts index d5df182..eaf69eb 100644 --- a/src/client/api/types.ts +++ b/src/client/api/types.ts @@ -10,8 +10,10 @@ export interface AuthResponse { } export interface ApiError { - error: string; - code?: string; + error: { + message: string; + code: string; + }; } export interface Tokens { |
