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

* chore: ui error handling should be specific to general

Specific errors should be checked before defaulting to a general
error handling
This commit is contained in:
Steven Masley
2024-08-19 13:28:43 -05:00
committed by GitHub
parent 422e044859
commit 755afa31cf
2 changed files with 18 additions and 6 deletions
+9 -6
View File
@@ -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;
};
@@ -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,