Skip to content

chore: ui error handling should be specific to general #14346

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Aug 19, 2024
Merged
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
15 changes: 9 additions & 6 deletions site/src/api/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,18 +115,21 @@ export const getErrorDetail = (error: unknown): string | undefined => {
return error.detail;
}

if (error instanceof Error) {
return "Please check the developer console for more details.";
}

if (isApiError(error)) {
// APIErrors that are empty still benefit from checking the developer
// console if no detail is provided. So only use the detail field if
// it is not empty.
if (isApiError(error) && error.response.data.detail) {
return error.response.data.detail;
}

if (isApiErrorResponse(error)) {
if (isApiErrorResponse(error) && error.detail) {
return error.detail;
}

if (error instanceof Error) {
return "Please check the developer console for more details.";
}

return undefined;
};

Expand Down
9 changes: 9 additions & 0 deletions site/src/components/Alert/ErrorAlert.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,15 @@ export const WithOnlyMessage: Story = {
},
};

export const APIErrorWithDetail: Story = {
args: {
error: mockApiError({
message: "Magic dust is missing",
detail: "without magic dust, the requested operation will never work",
}),
},
};

export const WithDismiss: Story = {
args: {
dismissible: true,
Expand Down
Loading