cpns / apps /web /src /lib /error-utils.ts
rogasper's picture
feat: enhance user experience with new components and improved error handling. Introduce ErrorFallback component for better error display, add pagination for admin content management, and implement dialogs for test session management. Update routing to include new components and improve accessibility with ARIA attributes. Refactor question formats and integrate debounced search functionality for admin features.
4c7b844
Raw
History Blame Contribute Delete
549 Bytes
/** Extract a human-readable message from an unknown error value.
* Safe to use in tRPC `onError` callbacks where the error type is `unknown`. */
export function getErrorMessage(err: unknown): string {
if (err instanceof Error) return err.message;
if (typeof err === "string") return err;
if (
err &&
typeof err === "object" &&
"message" in err &&
typeof (err as Record<string, unknown>).message === "string"
) {
return (err as Record<string, unknown>).message as string;
}
return "An unexpected error occurred";
}