mirror of
https://seed.radicle.dev/rad:z4V1sjrXqjvFdnCUbxPFqd5p4DtH5.git
synced 2026-11-16 03:40:37 +08:00
When a saved node (e.g. localhost) is down, the app previously showed a dead-end "Node not found" page with no way to navigate away. Now the not-found page displays the seed selector inline with the error title, showing which node failed and letting users switch to a different one directly. The same treatment applies when navigating to a repo on an unreachable node.
84 lines
2.3 KiB
TypeScript
84 lines
2.3 KiB
TypeScript
import type { ErrorRoute, NotFoundRoute } from "@app/lib/router/definitions";
|
|
import type { RepoRoute } from "@app/views/repos/router";
|
|
|
|
import { baseUrlToString } from "@app/lib/utils";
|
|
import { ResponseParseError, ResponseError } from "@http-client/lib/fetcher";
|
|
|
|
export function handleError(
|
|
error: Error | ResponseParseError | ResponseError,
|
|
route: RepoRoute,
|
|
): NotFoundRoute | ErrorRoute {
|
|
const url = baseUrlToString(route.node);
|
|
if (error instanceof ResponseError && error.status === 404) {
|
|
let subject;
|
|
|
|
if (route.resource === "repo.commit") {
|
|
subject = "Commit";
|
|
} else if (route.resource === "repo.issue") {
|
|
subject = "Issue";
|
|
} else if (route.resource === "repo.patch") {
|
|
subject = "Patch";
|
|
} else {
|
|
subject = "Repository";
|
|
}
|
|
|
|
return {
|
|
resource: "notFound",
|
|
params: { title: `${subject} not found` },
|
|
};
|
|
} else if (error instanceof ResponseError) {
|
|
return {
|
|
resource: "error",
|
|
params: {
|
|
error,
|
|
title: "Could not load this repository",
|
|
description: `Make sure you are able to connect to the seed <a href="${url}">${url}</a>.`,
|
|
},
|
|
};
|
|
} else if (error instanceof ResponseParseError) {
|
|
return {
|
|
resource: "error",
|
|
params: {
|
|
error,
|
|
title: "Could not parse the request",
|
|
description: error.description,
|
|
},
|
|
};
|
|
} else if (
|
|
error instanceof TypeError &&
|
|
error.message === "Failed to fetch"
|
|
) {
|
|
return {
|
|
resource: "notFound",
|
|
params: {
|
|
title: "Could not connect to",
|
|
description:
|
|
"The node may be offline or the address may be incorrect.\nSelect a different node to continue.",
|
|
baseUrl: route.node,
|
|
},
|
|
};
|
|
} else {
|
|
return {
|
|
resource: "error",
|
|
params: {
|
|
error,
|
|
title: "Could not load this repository",
|
|
description:
|
|
"You stumbled on an unknown error, we aren't exactly sure what happened.",
|
|
},
|
|
};
|
|
}
|
|
}
|
|
|
|
export function unreachableError(): NotFoundRoute | ErrorRoute {
|
|
return {
|
|
resource: "error",
|
|
params: {
|
|
error: undefined,
|
|
title: "Could not load this route",
|
|
description:
|
|
"You stumbled on an unknown error, we aren't exactly sure what happened.",
|
|
},
|
|
};
|
|
}
|