Skip to content

Commit 836ecbe

Browse files
committed
WIP
1 parent f2f52a8 commit 836ecbe

File tree

2 files changed

+42
-8
lines changed

2 files changed

+42
-8
lines changed

packages/admin/dashboard/src/components/utilities/error-boundary/error-boundary.tsx

Lines changed: 41 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,21 @@ export const ErrorBoundary = () => {
1111
const { t } = useTranslation()
1212

1313
let code: number | null = null
14+
let errorMessage: string | null = null
15+
16+
console.error(error)
1417

1518
if (isFetchError(error)) {
1619
if (error.status === 401) {
1720
return <Navigate to="/login" state={{ from: location }} replace />
1821
}
1922

2023
code = error.status ?? null
24+
// Extract the actual error message from the FetchError
25+
errorMessage = error.message || null
26+
} else if (error instanceof Error) {
27+
// For other Error types, use the error message
28+
errorMessage = error.message
2129
}
2230

2331
/**
@@ -26,32 +34,48 @@ export const ErrorBoundary = () => {
2634
* react-router-dom will sometimes swallow the error,
2735
* so this ensures that we always log it.
2836
*/
29-
if (process.env.NODE_ENV === "development") {
30-
console.error(error)
31-
}
37+
console.error(error)
3238

3339
let title: string
3440
let message: string
3541

3642
switch (code) {
3743
case 400:
3844
title = t("errorBoundary.badRequestTitle")
39-
message = t("errorBoundary.badRequestMessage")
45+
message = errorMessage || t("errorBoundary.badRequestMessage")
4046
break
4147
case 404:
4248
title = t("errorBoundary.notFoundTitle")
43-
message = t("errorBoundary.notFoundMessage")
49+
message = errorMessage || t("errorBoundary.notFoundMessage")
4450
break
4551
case 500:
4652
title = t("errorBoundary.internalServerErrorTitle")
47-
message = t("errorBoundary.internalServerErrorMessage")
53+
message = errorMessage || t("errorBoundary.internalServerErrorMessage")
4854
break
4955
default:
5056
title = t("errorBoundary.defaultTitle")
51-
message = t("errorBoundary.defaultMessage")
57+
message = errorMessage || t("errorBoundary.defaultMessage")
5258
break
5359
}
5460

61+
// Serialize error for display in development
62+
const errorDetails =
63+
process.env.NODE_ENV === "development"
64+
? JSON.stringify(
65+
error instanceof Error
66+
? {
67+
name: error.name,
68+
message: error.message,
69+
stack: error.stack,
70+
}
71+
: typeof error === "object" && error !== null
72+
? error
73+
: String(error),
74+
null,
75+
2
76+
)
77+
: null
78+
5579
return (
5680
<div className="flex size-full min-h-[calc(100vh-57px-24px)] items-center justify-center">
5781
<div className="flex flex-col gap-y-6">
@@ -67,6 +91,16 @@ export const ErrorBoundary = () => {
6791
>
6892
{message}
6993
</Text>
94+
{errorDetails && (
95+
<details className="mt-4 max-w-md">
96+
<summary className="text-ui-fg-muted cursor-pointer text-xs">
97+
Error details
98+
</summary>
99+
<pre className="bg-ui-bg-subtle mt-2 overflow-auto rounded p-2 text-xs">
100+
{errorDetails}
101+
</pre>
102+
</details>
103+
)}
70104
</div>
71105
</div>
72106
</div>

packages/admin/dashboard/src/i18n/translations/en.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,7 @@
358358
"internalServerErrorTitle": "500 - Internal server error",
359359
"internalServerErrorMessage": "An unexpected error occurred on the server. Please try again later.",
360360
"defaultTitle": "An error occurred",
361-
"defaultMessage": "An unexpected error occurred while rendering this page.",
361+
"defaultMessage": "An unexpected error occurred while rendering the page.",
362362
"noMatchMessage": "The page you are looking for does not exist.",
363363
"backToDashboard": "Back to dashboard"
364364
},

0 commit comments

Comments
 (0)