Skip to content

Commit

Permalink
Improve the ResponseParseError description
Browse files Browse the repository at this point in the history
In case of a `ResponseParseError` instead of comparing the versions of
httpd and the web client strictly, we should make sure to check if httpd
fulfills the web clients version requirement (to be the same major
version) and else fallback to a more verbose error about the different
versions.
  • Loading branch information
sebastinez committed Dec 2, 2024
1 parent 2075c32 commit df60d61
Showing 1 changed file with 7 additions and 14 deletions.
21 changes: 7 additions & 14 deletions http-client/lib/fetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import type { ZodIssue, ZodType, TypeOf } from "zod";

import config from "virtual:config";
import { compare } from "compare-versions";
import { satisfies } from "compare-versions";

export interface BaseUrl {
hostname: string;
Expand Down Expand Up @@ -52,26 +52,19 @@ export class ResponseParseError extends Error {
public constructor(
method: string,
body: unknown,
apiVersion: string | undefined,
apiVersion: string,
zodIssues: ZodIssue[],
path?: string,
) {
super("Failed to parse response body");
const browserVersion = config.nodes.apiVersion;
const nodeVersion = apiVersion;

let description: string;
if (
apiVersion === undefined ||
compare(apiVersion, config.nodes.apiVersion, "<")
) {
description = `The node you are fetching from seems to be outdated, make sure the httpd API version is at least ${config.nodes.apiVersion} currently ${apiVersion ?? "unknown"}.`;
} else if (
config.nodes.apiVersion === undefined ||
compare(apiVersion, config.nodes.apiVersion, ">")
) {
description = `The web client you are using is outdated, make sure it supports at least ${apiVersion} to interact with this node currently ${config.nodes.apiVersion ?? "unknown"}.`;
if (!satisfies(nodeVersion, `^${browserVersion}`)) {
description = `The node you are fetching from (v${nodeVersion}) doesn't match the version requirements of the web client ^${browserVersion}.`;
} else {
description =
"This is usually due to a version mismatch between the seed and the web interface.";
description = `The node (v${nodeVersion}) matches the version requirement of the web client (^${browserVersion}), but the web client isn't able to parse the response.`;
}
this.apiVersion = apiVersion;
this.description =
Expand Down

0 comments on commit df60d61

Please sign in to comment.