Skip to content

Commit

Permalink
Add connection reset error message (#288)
Browse files Browse the repository at this point in the history
  • Loading branch information
kmcginnes committed Apr 2, 2024
1 parent 2744e93 commit 2031129
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
19 changes: 19 additions & 0 deletions packages/graph-explorer/src/utils/createDisplayError.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,14 @@ describe("createDisplayError", () => {
});
});

it("Should handle connection reset", () => {
const result = createDisplayError({ code: "ECONNRESET" });
expect(result).toStrictEqual({
title: "Connection reset",
message: "Please check your connection and try again.",
});
});

it("Should handle connection refused as inner error", () => {
const error = new Error("Some error message string", {
cause: { code: "ECONNREFUSED" },
Expand All @@ -45,6 +53,17 @@ describe("createDisplayError", () => {
});
});

it("Should handle connection reset as inner error", () => {
const error = new Error("Some error message string", {
cause: { code: "ECONNRESET" },
});
const result = createDisplayError(error);
expect(result).toStrictEqual({
title: "Connection reset",
message: "Please check your connection and try again.",
});
});

it("Should handle AbortError", () => {
const result = createDisplayError({ name: "AbortError" });
expect(result).toStrictEqual({
Expand Down
6 changes: 6 additions & 0 deletions packages/graph-explorer/src/utils/createDisplayError.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ export function createDisplayError(error: any): DisplayError {
message: "Please check your connection and try again.",
};
}
if (error?.code === "ECONNRESET" || error?.cause?.code === "ECONNRESET") {
return {
title: "Connection reset",
message: "Please check your connection and try again.",
};
}

// Server timeout
if (
Expand Down

0 comments on commit 2031129

Please sign in to comment.