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); });