Fix [object Object] error when API returns structured error detail
The backend returns detail as an object for some errors (circular dependency, conflicts, etc.). The API client now JSON.stringifies object details so they can be properly parsed by error handlers like DependencyGraph.
This commit is contained in:
@@ -78,7 +78,13 @@ export class ForbiddenError extends ApiError {
|
|||||||
async function handleResponse<T>(response: Response): Promise<T> {
|
async function handleResponse<T>(response: Response): Promise<T> {
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
const error = await response.json().catch(() => ({ detail: 'Unknown error' }));
|
const error = await response.json().catch(() => ({ detail: 'Unknown error' }));
|
||||||
const message = error.detail || `HTTP ${response.status}`;
|
// Handle detail as string or object (backend may return structured errors)
|
||||||
|
let message: string;
|
||||||
|
if (typeof error.detail === 'object') {
|
||||||
|
message = JSON.stringify(error.detail);
|
||||||
|
} else {
|
||||||
|
message = error.detail || `HTTP ${response.status}`;
|
||||||
|
}
|
||||||
|
|
||||||
if (response.status === 401) {
|
if (response.status === 401) {
|
||||||
throw new UnauthorizedError(message);
|
throw new UnauthorizedError(message);
|
||||||
|
|||||||
Reference in New Issue
Block a user