Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 755afa3

Browse files
authored
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
1 parent 422e044 commit 755afa3

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

site/src/api/errors.ts

+9-6
Original file line numberDiff line numberDiff line change
@@ -115,18 +115,21 @@ export const getErrorDetail = (error: unknown): string | undefined => {
115115
return error.detail;
116116
}
117117

118-
if (error instanceof Error) {
119-
return "Please check the developer console for more details.";
120-
}
121-
122-
if (isApiError(error)) {
118+
// APIErrors that are empty still benefit from checking the developer
119+
// console if no detail is provided. So only use the detail field if
120+
// it is not empty.
121+
if (isApiError(error) && error.response.data.detail) {
123122
return error.response.data.detail;
124123
}
125124

126-
if (isApiErrorResponse(error)) {
125+
if (isApiErrorResponse(error) && error.detail) {
127126
return error.detail;
128127
}
129128

129+
if (error instanceof Error) {
130+
return "Please check the developer console for more details.";
131+
}
132+
130133
return undefined;
131134
};
132135

site/src/components/Alert/ErrorAlert.stories.tsx

+9
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,15 @@ export const WithOnlyMessage: Story = {
3434
},
3535
};
3636

37+
export const APIErrorWithDetail: Story = {
38+
args: {
39+
error: mockApiError({
40+
message: "Magic dust is missing",
41+
detail: "without magic dust, the requested operation will never work",
42+
}),
43+
},
44+
};
45+
3746
export const WithDismiss: Story = {
3847
args: {
3948
dismissible: true,

0 commit comments

Comments
 (0)