Skip to content

The open-source AI voice studio. Clone, dictate, create.

fix error detail serialization producing [object Object] in error messages

Jamie Pine664178f0cfd5
diff --git a/app/src/lib/api/client.ts b/app/src/lib/api/client.ts
index 036af3df..98f98182 100644
--- a/app/src/lib/api/client.ts
+++ b/app/src/lib/api/client.ts
@@ -35,6 +35,21 @@ import type {
WhisperModelSize,
} from './types';
+function formatErrorDetail(detail: unknown, fallback: string): string {
+ if (typeof detail === 'string') return detail;
+ if (Array.isArray(detail)) {
+ return detail
+ .map((e: Record<string, unknown>) => e.msg || e.message || JSON.stringify(e))
+ .join('; ');
+ }
+ if (detail && typeof detail === 'object') {
+ const obj = detail as Record<string, unknown>;
+ if (typeof obj.message === 'string') return obj.message;
+ return JSON.stringify(detail);
+ }
+ return fallback;
+}
+
class ApiClient {
private getBaseUrl(): string {
const serverUrl = useServerStore.getState().serverUrl;
@@ -55,7 +70,7 @@ class ApiClient {
const error = await response.json().catch(() => ({
detail: response.statusText,
}));
- throw new Error(error.detail || `HTTP error! status: ${response.status}`);
+ throw new Error(formatErrorDetail(error.detail, `HTTP error! status: ${response.status}`));
}
return response.json();
@@ -114,7 +129,7 @@ class ApiClient {
const error = await response.json().catch(() => ({
detail: response.statusText,
}));
- throw new Error(error.detail || `HTTP error! status: ${response.status}`);
+ throw new Error(formatErrorDetail(error.detail, `HTTP error! status: ${response.status}`));
}
return response.json();
@@ -148,7 +163,7 @@ class ApiClient {
const error = await response.json().catch(() => ({
detail: response.statusText,
}));
- throw new Error(error.detail || `HTTP error! status: ${response.status}`);
+ throw new Error(formatErrorDetail(error.detail, `HTTP error! status: ${response.status}`));
}
return response.blob();
@@ -168,7 +183,7 @@ class ApiClient {
const error = await response.json().catch(() => ({
detail: response.statusText,
}));
- throw new Error(error.detail || `HTTP error! status: ${response.status}`);
+ throw new Error(formatErrorDetail(error.detail, `HTTP error! status: ${response.status}`));
}
return response.json();
@@ -188,7 +203,7 @@ class ApiClient {
const error = await response.json().catch(() => ({
detail: response.statusText,
}));
- throw new Error(error.detail || `HTTP error! status: ${response.status}`);
+ throw new Error(formatErrorDetail(error.detail, `HTTP error! status: ${response.status}`));
}
return response.json();
@@ -258,7 +273,7 @@ class ApiClient {
const error = await response.json().catch(() => ({
detail: response.statusText,
}));
- throw new Error(error.detail || `HTTP error! status: ${response.status}`);
+ throw new Error(formatErrorDetail(error.detail, `HTTP error! status: ${response.status}`));
}
return response.blob();
@@ -272,7 +287,7 @@ class ApiClient {
const error = await response.json().catch(() => ({
detail: response.statusText,
}));
- throw new Error(error.detail || `HTTP error! status: ${response.status}`);
+ throw new Error(formatErrorDetail(error.detail, `HTTP error! status: ${response.status}`));
}
return response.blob();
@@ -298,7 +313,7 @@ class ApiClient {
const error = await response.json().catch(() => ({
detail: response.statusText,
}));
- throw new Error(error.detail || `HTTP error! status: ${response.status}`);
+ throw new Error(formatErrorDetail(error.detail, `HTTP error! status: ${response.status}`));
}
return response.json();
@@ -343,7 +358,7 @@ class ApiClient {
const error = await response.json().catch(() => ({
detail: response.statusText,
}));
- throw new Error(error.detail || `HTTP error! status: ${response.status}`);
+ throw new Error(formatErrorDetail(error.detail, `HTTP error! status: ${response.status}`));
}
return response.json();
@@ -616,7 +631,7 @@ class ApiClient {
const error = await response.json().catch(() => ({
detail: response.statusText,
}));
- throw new Error(error.detail || `HTTP error! status: ${response.status}`);
+ throw new Error(formatErrorDetail(error.detail, `HTTP error! status: ${response.status}`));
}
return response.blob();
@@ -713,7 +728,7 @@ class ApiClient {
const error = await response.json().catch(() => ({
detail: response.statusText,
}));
- throw new Error(error.detail || `HTTP error! status: ${response.status}`);
+ throw new Error(formatErrorDetail(error.detail, `HTTP error! status: ${response.status}`));
}
return response.blob();