27 lines
932 B
TypeScript
27 lines
932 B
TypeScript
import type { HandleClientError } from "@sveltejs/kit";
|
|
import { TRPCClientError } from "@trpc/client";
|
|
|
|
const CHECK_CONNECTION = "Die Seite konnte nicht geladen werden, prüfen sie ihre Verbindung";
|
|
|
|
export const handleError: HandleClientError = ({ error, message, status }) => {
|
|
// If there are client-side errors, SvelteKit always returns the nondescript
|
|
// "Internal error" message. The most common errors should be mapped to a more
|
|
// detailed description
|
|
if (status === 500) {
|
|
// eslint-disable-next-line no-console
|
|
console.error("Client error:", error);
|
|
|
|
if (
|
|
error instanceof TypeError
|
|
&& error.message.includes("dynamically imported module")
|
|
) {
|
|
// Could not load JS module
|
|
message = CHECK_CONNECTION;
|
|
} else if (error instanceof TRPCClientError && !error.data) {
|
|
// Could not load fetched data
|
|
message = CHECK_CONNECTION;
|
|
}
|
|
}
|
|
|
|
return { message };
|
|
};
|