Skip to content

Commit 234460f

Browse files
committed
fix: make error extraction more robust
- Handle both FastAPI wrapped ({detail: {...}}) and unwrapped errors - isUpgradeError now checks err.detail.error OR err.error - extractErrorMessage prioritizes .message field, truncates long JSON
1 parent b46401e commit 234460f

1 file changed

Lines changed: 14 additions & 7 deletions

File tree

frontend/src/components/dashboard/DashboardHome.tsx

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,19 +35,26 @@ const MAX_FREE_REPOS = 3
3535

3636
// Extract error message from API response (handles nested detail objects)
3737
function extractErrorMessage(err: any, fallback: string): string {
38-
if (typeof err?.detail === 'string') return err.detail
39-
if (typeof err?.detail?.message === 'string') return err.detail.message
38+
// FastAPI wraps in detail, but handle both cases
39+
const detail = err?.detail || err
40+
41+
if (typeof detail === 'string') return detail
42+
if (typeof detail?.message === 'string') return detail.message
4043
if (typeof err?.message === 'string') return err.message
41-
// Last resort: try to stringify if it's an object
42-
if (err?.detail && typeof err.detail === 'object') {
43-
return JSON.stringify(err.detail)
44+
45+
// Last resort: stringify (but keep it short)
46+
if (detail && typeof detail === 'object') {
47+
const msg = detail.message || detail.error
48+
if (msg) return String(msg)
49+
return JSON.stringify(detail).slice(0, 200)
4450
}
4551
return fallback
4652
}
4753

48-
// Check if error is a limit/upgrade error
54+
// Check if error is a limit/upgrade error (handles both wrapped and unwrapped)
4955
function isUpgradeError(err: any): boolean {
50-
const code = err?.detail?.error || err?.detail?.error_code
56+
const detail = err?.detail || err
57+
const code = detail?.error || detail?.error_code
5158
return ['REPO_TOO_LARGE', 'REPO_LIMIT_REACHED'].includes(code)
5259
}
5360

0 commit comments

Comments
 (0)