From d7dfa9ed7626ddc86c82c666d9c3d72edeb962a0 Mon Sep 17 00:00:00 2001 From: Vishwak Thatikonda Date: Mon, 20 Jul 2026 12:11:23 -0700 Subject: [PATCH] fix: show a friendly Access denied message for 403 responses A 403 previously fell through to the catch-all NetworkError branch, showing the unfriendly "Network Response 403" title with either the raw server response or a generic message. Since a 403 can be caused by several things (credentials, permissions, proxy configuration), the new message stays generic and points the user at what they can reasonably check. Fixes #1977 --- .../src/utils/createDisplayError.test.ts | 24 +++++++++++++++++++ .../src/utils/createDisplayError.ts | 11 +++++++++ 2 files changed, 35 insertions(+) diff --git a/packages/graph-explorer/src/utils/createDisplayError.test.ts b/packages/graph-explorer/src/utils/createDisplayError.test.ts index 65dcd24ca..1e15d1aca 100644 --- a/packages/graph-explorer/src/utils/createDisplayError.test.ts +++ b/packages/graph-explorer/src/utils/createDisplayError.test.ts @@ -178,6 +178,30 @@ describe("createDisplayError", () => { }); }); + it("Should handle access denied error", () => { + const result = createDisplayError( + new NetworkError("Network error", 403, null), + ); + expect(result).toStrictEqual({ + title: "Access denied", + message: + "The server refused this request. Check that your connection credentials and permissions are correct, then try again.", + }); + }); + + it("Should handle access denied error ignoring raw server data", () => { + const result = createDisplayError( + new NetworkError("Network error", 403, { + message: '{"requestId":"abc","code":"AccessDeniedException"}', + }), + ); + expect(result).toStrictEqual({ + title: "Access denied", + message: + "The server refused this request. Check that your connection credentials and permissions are correct, then try again.", + }); + }); + it("Should handle too many requests error", () => { const result = createDisplayError( new NetworkError("Network error", 429, null), diff --git a/packages/graph-explorer/src/utils/createDisplayError.ts b/packages/graph-explorer/src/utils/createDisplayError.ts index b3d33bdca..36048e9dc 100644 --- a/packages/graph-explorer/src/utils/createDisplayError.ts +++ b/packages/graph-explorer/src/utils/createDisplayError.ts @@ -122,6 +122,17 @@ export function createDisplayError(error: any): DisplayError { }; } + if (error.statusCode === 403) { + // A 403 can be caused by several things (credentials, permissions, + // proxy configuration), so the message stays generic and points the + // user at what they can reasonably check. + return { + title: "Access denied", + message: + "The server refused this request. Check that your connection credentials and permissions are correct, then try again.", + }; + } + if (error.statusCode === 429) { return { title: "Too Many Requests",