From 1dec1ec4ad8123f7834ba3707f261cbc95ad5588 Mon Sep 17 00:00:00 2001 From: Jake Howell Date: Thu, 26 Feb 2026 02:35:25 +1100 Subject: [PATCH] fix: add `getValidationErrorMessage()` to `getErrorDetail()` (#22229) This pull-request ensures that we render the validation errors back to the user when the errors contain context as to why. Previously when we attempted to we'd guide the user to simply checkout the Dev Console. This wasn't a great approach as the user still would have to decode this, the context is explicit now. The error messages could use some improvement, but we make use of this already in [`Filter.tsx`](https://github.com/coder/coder/blob/main/site/src/components/Filter/Filter.tsx#L259) so at-least its inline. image --------- Co-authored-by: Phorcys <57866459+phorcys420@users.noreply.github.com> --- site/src/api/errors.ts | 9 +++++++++ .../UserSettingsPage/AccountPage/AccountPage.test.tsx | 4 ++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/site/src/api/errors.ts b/site/src/api/errors.ts index 5573b6de3f..d2c1043b3d 100644 --- a/site/src/api/errors.ts +++ b/site/src/api/errors.ts @@ -127,6 +127,15 @@ export const getErrorDetail = (error: unknown): string | undefined => { return error.detail; } + if ( + isApiValidationError(error) && + // Ensure that the validations array is not `[]` (empty array). + Array.isArray(error.response.data.validations) && + error.response.data.validations.length > 0 + ) { + return getValidationErrorMessage(error); + } + if (error instanceof Error) { return "Please check the developer console for more details."; } diff --git a/site/src/pages/UserSettingsPage/AccountPage/AccountPage.test.tsx b/site/src/pages/UserSettingsPage/AccountPage/AccountPage.test.tsx index d4b6cc9302..f0a5514d0b 100644 --- a/site/src/pages/UserSettingsPage/AccountPage/AccountPage.test.tsx +++ b/site/src/pages/UserSettingsPage/AccountPage/AccountPage.test.tsx @@ -65,10 +65,10 @@ describe("AccountPage", () => { renderWithAuth(); await fillAndSubmitForm(); - const errorMessage = await screen.findByText( + const errorMessages = await screen.findAllByText( "Username is already in use", ); - expect(errorMessage).toBeDefined(); + expect(errorMessages.length).toBeGreaterThanOrEqual(2); expect(API.updateProfile).toBeCalledTimes(1); expect(API.updateProfile).toBeCalledWith("me", newData); });