From 98bdb6b4ae70741ca02a3032f9caec956af101d4 Mon Sep 17 00:00:00 2001 From: Steven Masley Date: Mon, 19 Aug 2024 08:42:35 -0500 Subject: [PATCH 1/6] chore: ui error handling should be specific to general Specific errors should be checked before defaulting to a general error handling --- site/src/api/errors.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/site/src/api/errors.ts b/site/src/api/errors.ts index 51572f2940b6a..2ebd309eed5af 100644 --- a/site/src/api/errors.ts +++ b/site/src/api/errors.ts @@ -115,10 +115,6 @@ 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)) { return error.response.data.detail; } @@ -127,6 +123,10 @@ export const getErrorDetail = (error: unknown): string | undefined => { return error.detail; } + if (error instanceof Error) { + return "Please check the developer console for more details."; + } + return undefined; }; From b8bea993748ac5d44620bfbe4fe169b4d8f09227 Mon Sep 17 00:00:00 2001 From: Steven Masley Date: Mon, 19 Aug 2024 08:50:42 -0500 Subject: [PATCH 2/6] ignore empty detail fields --- site/src/api/errors.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/site/src/api/errors.ts b/site/src/api/errors.ts index 2ebd309eed5af..bfa2115316638 100644 --- a/site/src/api/errors.ts +++ b/site/src/api/errors.ts @@ -115,11 +115,14 @@ export const getErrorDetail = (error: unknown): string | undefined => { return error.detail; } - 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; } From 92aad66be42c812f52b4a8fb7221f395ef20de8f Mon Sep 17 00:00:00 2001 From: Steven Masley Date: Mon, 19 Aug 2024 12:15:02 -0500 Subject: [PATCH 3/6] fix comment lenght --- site/src/api/errors.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/site/src/api/errors.ts b/site/src/api/errors.ts index bfa2115316638..b40743177c0df 100644 --- a/site/src/api/errors.ts +++ b/site/src/api/errors.ts @@ -115,9 +115,8 @@ export const getErrorDetail = (error: unknown): string | undefined => { return error.detail; } - // 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. + // 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; } From 8ab1dd4be9528e13fd495077d917c2e30cf93a53 Mon Sep 17 00:00:00 2001 From: Steven Masley Date: Mon, 19 Aug 2024 12:17:01 -0500 Subject: [PATCH 4/6] add story for api error with detail --- site/src/components/Alert/ErrorAlert.stories.tsx | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/site/src/components/Alert/ErrorAlert.stories.tsx b/site/src/components/Alert/ErrorAlert.stories.tsx index 2b2a6b3f0b6c3..5cf8ddd39958e 100644 --- a/site/src/components/Alert/ErrorAlert.stories.tsx +++ b/site/src/components/Alert/ErrorAlert.stories.tsx @@ -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, From 7b79132797103b35f49ce2df49f0a0f8e1477937 Mon Sep 17 00:00:00 2001 From: Steven Masley Date: Mon, 19 Aug 2024 12:18:18 -0500 Subject: [PATCH 5/6] fix comment length with proper spaces before --- site/src/api/errors.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/site/src/api/errors.ts b/site/src/api/errors.ts index b40743177c0df..e79649d5d8647 100644 --- a/site/src/api/errors.ts +++ b/site/src/api/errors.ts @@ -115,8 +115,9 @@ export const getErrorDetail = (error: unknown): string | undefined => { return error.detail; } - // 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. + // 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; } From 1b39235996ceddc611ea3fc12729a35de4f92fd3 Mon Sep 17 00:00:00 2001 From: Steven Masley Date: Mon, 19 Aug 2024 12:43:07 -0500 Subject: [PATCH 6/6] fmt --- site/src/api/errors.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/site/src/api/errors.ts b/site/src/api/errors.ts index e79649d5d8647..f1e63d1e39caf 100644 --- a/site/src/api/errors.ts +++ b/site/src/api/errors.ts @@ -115,8 +115,8 @@ export const getErrorDetail = (error: unknown): string | undefined => { return error.detail; } - // APIErrors that are empty still benefit from checking the developer - // console if no detail is provided. So only use the detail field if + // 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;