Improve catching of errors when loading routes

- 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.
This commit is contained in:
Sebastian Martinez
2024-02-15 13:26:11 -03:00
parent 8450f0cd9c
commit d216caec7d
24 changed files with 389 additions and 185 deletions
+2 -1
View File
@@ -178,7 +178,8 @@
{#if error}
<ErrorMessage
message="Not able to load more projects from this node"
title="Not able to load more projects from this node"
description="You either loaded all remaining projects, or there was a network issue with this seed"
{error} />
{/if}
</div>
+46
View File
@@ -0,0 +1,46 @@
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.",
},
};
}
}
+5 -22
View File
@@ -1,13 +1,12 @@
import type { BaseUrl } from "@httpd-client";
import type {
LoadErrorRoute,
NotFoundRoute,
} from "@app/lib/router/definitions";
import type { ErrorRoute, NotFoundRoute } from "@app/lib/router/definitions";
import type { ProjectWithListingData } from "@app/lib/projects";
import { HttpdClient } from "@httpd-client";
import { config } from "@app/lib/config";
import { baseUrlToUrl } from "@app/lib/utils";
import { getProjectsListingData } from "@app/lib/projects";
import { handleError } from "@app/views/nodes/error";
export interface NodesRouteParams {
baseUrl: BaseUrl;
@@ -70,7 +69,7 @@ export function nodePath(baseUrl: BaseUrl) {
export async function loadNodeRoute(
params: NodesRouteParams,
): Promise<NodesLoadedRoute | NotFoundRoute | LoadErrorRoute> {
): Promise<NodesLoadedRoute | NotFoundRoute | ErrorRoute> {
const api = new HttpdClient(params.baseUrl);
try {
const projectPageIndex = 0;
@@ -91,22 +90,6 @@ export async function loadNodeRoute(
},
};
} catch (error: any) {
if (error.message === "Failed to fetch") {
return {
resource: "notFound",
params: {
title: "Node not found",
},
};
} else {
return {
resource: "loadError",
params: {
title: "Not able to load this node",
errorMessage: error.message,
stackTrace: error.stackTrace,
},
};
}
return handleError(error, baseUrlToUrl(api.baseUrl).toString());
}
}