fix: show proper error message instead of [object Object] in mail account wizard

Agent-Logs-Url: https://github.com/christianlouis/InboxConverge/sessions/404b7221-8b33-4178-8601-6c0815552c7f

Co-authored-by: christianlouis <361235+christianlouis@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot]
2026-03-28 22:14:58 +00:00
parent 5ff5cb54be
commit 191fee9be4
2 changed files with 21 additions and 8 deletions
@@ -116,6 +116,18 @@ export function AddMailAccountModal({ account, onClose }: AddMailAccountModalPro
}
};
const extractErrorMessage = (error: unknown, fallback: string): string => {
interface FastAPIValidationError { msg: string; loc?: unknown[]; type?: string }
const detail = (error as { response?: { data?: { detail?: unknown } } })?.response?.data?.detail;
if (typeof detail === 'string') return detail;
if (Array.isArray(detail)) {
const msgs = (detail as FastAPIValidationError[]).map((d) => d?.msg ?? JSON.stringify(d));
return msgs.join('; ');
}
if (error instanceof Error && error.message) return error.message;
return fallback;
};
const handleTestConnection = async () => {
setTestStatus('testing');
setTestMessage('');
@@ -150,10 +162,7 @@ export function AddMailAccountModal({ account, onClose }: AddMailAccountModalPro
}
} catch (error) {
setTestStatus('error');
const errorMessage = error instanceof Error && 'response' in error
? (error as { response?: { data?: { detail?: string } } }).response?.data?.detail
: null;
setTestMessage(errorMessage || 'Connection failed');
setTestMessage(extractErrorMessage(error, 'Connection failed'));
}
};
@@ -188,10 +197,7 @@ export function AddMailAccountModal({ account, onClose }: AddMailAccountModalPro
await createMutation.mutateAsync(formData);
}
} catch (error) {
const errorMessage = error instanceof Error && 'response' in error
? (error as { response?: { data?: { detail?: string } } }).response?.data?.detail
: null;
alert(errorMessage || 'Failed to save account');
alert(extractErrorMessage(error, 'Failed to save account'));
}
};