mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
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:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user