mirror of
https://github.com/tale/headplane.git
synced 2026-08-31 01:09:25 +00:00
fix: read aggregate and error cause bubbles
This commit is contained in:
@@ -8,11 +8,34 @@ interface Props {
|
|||||||
type?: 'full' | 'embedded';
|
type?: 'full' | 'embedded';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function getMessage(error: Error | unknown) {
|
||||||
|
if (!(error instanceof Error)) {
|
||||||
|
return "An unknown error occurred";
|
||||||
|
}
|
||||||
|
|
||||||
|
let rootError = error;
|
||||||
|
|
||||||
|
// Traverse the error chain to find the root cause
|
||||||
|
if (error.cause) {
|
||||||
|
rootError = error.cause;
|
||||||
|
while (rootError.cause) {
|
||||||
|
rootError = rootError.cause;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// If we are aggregate, concat into a single message
|
||||||
|
if (rootError instanceof AggregateError) {
|
||||||
|
return rootError.errors.map((error) => error.message).join('\n');
|
||||||
|
}
|
||||||
|
|
||||||
|
return rootError.message;
|
||||||
|
}
|
||||||
|
|
||||||
export function ErrorPopup({ type = 'full' }: Props) {
|
export function ErrorPopup({ type = 'full' }: Props) {
|
||||||
const error = useRouteError();
|
const error = useRouteError();
|
||||||
const routing = isRouteErrorResponse(error);
|
const routing = isRouteErrorResponse(error);
|
||||||
const message =
|
const message = getMessage(error);
|
||||||
error instanceof Error ? error.message : 'An unexpected error occurred';
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
|
|||||||
Reference in New Issue
Block a user