mirror of
https://seed.radicle.dev/rad:z4V1sjrXqjvFdnCUbxPFqd5p4DtH5.git
synced 2026-11-14 02:50:51 +08:00
- Handle ResponseParseErros, ResponseErrors and normal errors differently. - Show them all in the same `LoadError` view - Add a subtitle to give users some more information on what could have gone wrong. - Add more properties to the copyable error message to make debugging easier.
47 lines
1.4 KiB
TypeScript
47 lines
1.4 KiB
TypeScript
import type { ErrorRoute, NotFoundRoute } from "@app/lib/router/definitions";
|
|
import { ResponseParseError, ResponseError } from "@httpd-client/lib/fetcher";
|
|
|
|
export function handleError(
|
|
error: Error | ResponseParseError | ResponseError,
|
|
url: string,
|
|
): NotFoundRoute | ErrorRoute {
|
|
if (error instanceof ResponseParseError) {
|
|
return {
|
|
resource: "error",
|
|
params: {
|
|
error,
|
|
title: "Could not parse the request",
|
|
description:
|
|
"The response received from the seed does not match the expected schema, this is usually due to a version mismatch between the seed and the web interface.",
|
|
},
|
|
};
|
|
} else if (error instanceof ResponseError) {
|
|
return {
|
|
resource: "error",
|
|
params: {
|
|
error,
|
|
title: "Could not load this node",
|
|
description: `You're trying to access a node that is not reachable, make sure the address <a href="${url}">${url}</a> is correct and the right ports are exposed if its your node.`,
|
|
},
|
|
};
|
|
} else if (
|
|
error instanceof TypeError &&
|
|
error.message === "Failed to fetch"
|
|
) {
|
|
return {
|
|
resource: "notFound",
|
|
params: { title: "Node not found" },
|
|
};
|
|
} else {
|
|
return {
|
|
resource: "error",
|
|
params: {
|
|
error,
|
|
title: "Could not load this node",
|
|
description:
|
|
"You stumbled on an unknown error, we aren't exactly sure what happened.",
|
|
},
|
|
};
|
|
}
|
|
}
|