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
+4 -1
View File
@@ -493,7 +493,10 @@
class="diff-error txt-monospace txt-small"
style:border-radius="var(--border-radius-small">
<ErrorMessage
message="Failed to load diff for this revision"
title="Failed to load diff for this revision"
description="Make sure you are able to connect to the seed <code>${utils
.baseUrlToUrl(api.baseUrl)
.toString()}</code>"
{error} />
</div>
{/if}
+9 -3
View File
@@ -8,9 +8,10 @@
} from "@httpd-client";
import type { Route } from "@app/lib/router";
import { HttpdClient } from "@httpd-client";
import { groupCommits } from "@app/lib/commit";
import { COMMITS_PER_PAGE } from "./router";
import { HttpdClient } from "@httpd-client";
import { baseUrlToUrl } from "@app/lib/utils";
import { groupCommits } from "@app/lib/commit";
import Button from "@app/components/Button.svelte";
import CommitTeaser from "./Commit/CommitTeaser.svelte";
@@ -157,7 +158,12 @@
{#if error}
<div class="message">
<ErrorMessage message="Couldn't load commits" {error} />
<ErrorMessage
title="Couldn't load commits"
description="Make sure you are able to connect to the seed <code>${baseUrlToUrl(
api.baseUrl,
).toString()}</code>"
{error} />
</div>
{/if}
</Layout>
+2 -1
View File
@@ -127,6 +127,7 @@
</div>
{:else}
<ErrorMessage
message="Couldn't access issue creation. Make sure you're authenticated." />
title="Not able to create a new issue"
description="Couldn't access issue creation. Make sure you're authenticated." />
{/if}
</Layout>
+7 -2
View File
@@ -5,7 +5,7 @@
import { ISSUES_PER_PAGE } from "./router";
import { closeFocused } from "@app/components/Popover.svelte";
import { httpdStore } from "@app/lib/httpd";
import { isLocal } from "@app/lib/utils";
import { baseUrlToUrl, isLocal } from "@app/lib/utils";
import capitalize from "lodash/capitalize";
import Button from "@app/components/Button.svelte";
@@ -174,7 +174,12 @@
</List>
{#if error}
<ErrorMessage message="Couldn't load issues" {error} />
<ErrorMessage
title="Couldn't load issues"
description="Please make sure you are able to connect to the seed <code>${baseUrlToUrl(
api.baseUrl,
).toString()}</code>"
{error} />
{/if}
{#if project.issues[state] === 0}
+7 -2
View File
@@ -6,7 +6,7 @@
import { PATCHES_PER_PAGE } from "./router";
import { httpdStore } from "@app/lib/httpd";
import { isLocal } from "@app/lib/utils";
import { baseUrlToUrl, isLocal } from "@app/lib/utils";
import Button from "@app/components/Button.svelte";
import DropdownList from "@app/components/DropdownList.svelte";
@@ -193,7 +193,12 @@
</List>
{#if error}
<ErrorMessage message="Couldn't load patches" {error} />
<ErrorMessage
title="Couldn't load patches"
description="Please make sure you are able to connect to the seed <code>${baseUrlToUrl(
api.baseUrl,
).toString()}</code>"
{error} />
{/if}
{#if project.patches[state] === 0}
+59
View File
@@ -0,0 +1,59 @@
import type { ErrorRoute, NotFoundRoute } from "@app/lib/router/definitions";
import type { ProjectRoute } from "@app/views/projects/router";
import { baseUrlToUrl } from "@app/lib/utils";
import { ResponseParseError, ResponseError } from "@httpd-client/lib/fetcher";
export function handleError(
error: Error | ResponseParseError | ResponseError,
route: ProjectRoute,
): NotFoundRoute | ErrorRoute {
const url = baseUrlToUrl(route.node);
if (error instanceof ResponseError && error.status === 404) {
let subject;
if (route.resource === "project.commit") {
subject = "Commit";
} else if (route.resource === "project.issue") {
subject = "Issue";
} else if (route.resource === "project.patch") {
subject = "Patch";
} else {
subject = "Project";
}
return {
resource: "notFound",
params: { title: `${subject} not found` },
};
} else if (error instanceof ResponseError) {
return {
resource: "error",
params: {
error,
title: "Could not load this project",
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:
"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 {
return {
resource: "error",
params: {
error,
title: "Could not load this project",
description:
"You stumbled on an unknown error, we aren't exactly sure what happened.",
},
};
}
}
+5 -35
View File
@@ -1,7 +1,4 @@
import type {
LoadErrorRoute,
NotFoundRoute,
} from "@app/lib/router/definitions";
import type { ErrorRoute, NotFoundRoute } from "@app/lib/router/definitions";
import type {
BaseUrl,
Blob,
@@ -21,9 +18,10 @@ import type {
import * as Syntax from "@app/lib/syntax";
import * as httpd from "@app/lib/httpd";
import { config } from "@app/lib/config";
import { HttpdClient } from "@httpd-client";
import { ResponseError } from "@httpd-client/lib/fetcher";
import { config } from "@app/lib/config";
import { handleError } from "@app/views/projects/error";
import { nodePath } from "@app/views/nodes/router";
import { unreachable } from "@app/lib/utils";
@@ -271,7 +269,7 @@ async function isLocalNodeSeeding(route: ProjectRoute): Promise<boolean> {
export async function loadProjectRoute(
route: ProjectRoute,
): Promise<ProjectLoadedRoute | LoadErrorRoute | NotFoundRoute> {
): Promise<ProjectLoadedRoute | ErrorRoute | NotFoundRoute> {
const api = new HttpdClient(route.node);
const rawPath = (commit?: string) =>
`${route.node.scheme}://${route.node.hostname}:${route.node.port}/raw/${
@@ -341,35 +339,7 @@ export async function loadProjectRoute(
return unreachable(route);
}
} catch (error: any) {
if (error?.status === 404) {
let subject;
if (route.resource === "project.commit") {
subject = "Commit";
} else if (route.resource === "project.issue") {
subject = "Issue";
} else if (route.resource === "project.patch") {
subject = "Patch";
} else {
subject = "Project";
}
return {
resource: "notFound",
params: {
title: `${subject} not found`,
},
};
} else {
return {
resource: "loadError",
params: {
title: "Could not load this project",
errorMessage: error.message,
stackTrace: error.stack,
},
};
}
return handleError(error, route);
}
}