From 73ee02825f57d971f6f660fc5277d4aa268702ff Mon Sep 17 00:00:00 2001 From: nsfisis Date: Wed, 31 Dec 2025 19:39:47 +0900 Subject: fix(client): parse nested error object in API responses MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- src/client/api/client.test.ts | 6 ++++-- src/client/api/client.ts | 5 +++-- src/client/api/types.ts | 6 ++++-- 3 files changed, 11 insertions(+), 6 deletions(-) (limited to 'src/client') 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 { -- cgit v1.2.3-70-g09d2