Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions packages/graph-explorer/src/utils/createDisplayError.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
11 changes: 11 additions & 0 deletions packages/graph-explorer/src/utils/createDisplayError.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down