fixed error parsing in mcp

This commit is contained in:
shivam 2026-02-04 17:45:55 -08:00
parent 6a73e5bd37
commit e699b21878
3 changed files with 23 additions and 7 deletions

View file

@ -21,13 +21,18 @@ export interface RouterFieldsResponse {
const routerFieldsKeys = createQueryKeys("routerFields");
const deriveErrorMessage = (errorData: any): string => {
return (
const raw =
(errorData?.error && (errorData.error.message || errorData.error)) ||
errorData?.message ||
errorData?.detail ||
errorData?.error ||
JSON.stringify(errorData)
);
JSON.stringify(errorData);
// Backend often returns { detail: { error: "..." } }; avoid showing [object Object]
if (typeof raw === "object" && raw !== null) {
const msg = raw.error ?? raw.message;
return typeof msg === "string" ? msg : JSON.stringify(raw);
}
return String(raw);
};
const getRouterFields = async (accessToken: string): Promise<RouterFieldsResponse> => {

View file

@ -305,7 +305,13 @@ const CreateMCPServer: React.FC<CreateMCPServerProps> = ({
onCreateSuccess(response);
}
} catch (error) {
NotificationsManager.fromBackend("Error creating MCP Server: " + error);
const message =
error instanceof Error
? error.message
: typeof error === "object" && error !== null && "error" in error
? String((error as { error: unknown }).error)
: String(error);
NotificationsManager.fromBackend("Error creating MCP Server: " + message);
} finally {
setIsLoading(false);
}

View file

@ -8690,13 +8690,18 @@ export const perUserAnalyticsCall = async (
};
export const deriveErrorMessage = (errorData: any): string => {
return (
const raw =
(errorData?.error && (errorData.error.message || errorData.error)) ||
errorData?.message ||
errorData?.detail ||
errorData?.error ||
JSON.stringify(errorData)
);
JSON.stringify(errorData);
// Backend often returns { detail: { error: "..." } }; avoid showing [object Object]
if (typeof raw === "object" && raw !== null) {
const msg = raw.error ?? raw.message;
return typeof msg === "string" ? msg : JSON.stringify(raw);
}
return String(raw);
};
export interface LoginRequest {