]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-19967 Fix error message parsing when updating user
authorguillaume-peoch-sonarsource <guillaume.peoch@sonarsource.com>
Mon, 21 Aug 2023 15:31:30 +0000 (17:31 +0200)
committersonartech <sonartech@sonarsource.com>
Tue, 22 Aug 2023 20:03:05 +0000 (20:03 +0000)
server/sonar-web/src/main/js/apps/users/components/UserForm.tsx
server/sonar-web/src/main/js/helpers/request.ts

index a605cbdd5c24a8764a2f9d4812f8c3408a90b568..cc7866c0d591cbbde1df44712c728ee0b2c4e38d 100644 (file)
@@ -25,7 +25,7 @@ import MandatoryFieldMarker from '../../../components/ui/MandatoryFieldMarker';
 import MandatoryFieldsExplanation from '../../../components/ui/MandatoryFieldsExplanation';
 import { throwGlobalError } from '../../../helpers/error';
 import { translate, translateWithParameters } from '../../../helpers/l10n';
-import { parseMessage } from '../../../helpers/request';
+import { parseError } from '../../../helpers/request';
 import { usePostUserMutation, useUpdateUserMutation } from '../../../queries/users';
 import { RestUserDetailed } from '../../../types/users';
 import UserScmAccountInput from './UserScmAccountInput';
@@ -56,7 +56,7 @@ export default function UserForm(props: Props) {
     if (![BAD_REQUEST, INTERNAL_SERVER_ERROR].includes(response.status)) {
       throwGlobalError(response);
     } else {
-      parseMessage(response).then((errorMsg) => setError(errorMsg), throwGlobalError);
+      parseError(response).then((errorMsg) => setError(errorMsg), throwGlobalError);
     }
   };
 
index 5a1537dfb816152989de83da759f3c51778ff4d9..d48f498855d9e6e96db77241105c4883f68ef4bd 100644 (file)
@@ -183,17 +183,7 @@ export function parseText(response: Response): Promise<string> {
 export function parseError(response: Response): Promise<string> {
   const DEFAULT_MESSAGE = translate('default_error_message');
   return parseJSON(response)
-    .then(({ errors }) => errors.map((error: any) => error.msg).join('. '))
-    .catch(() => DEFAULT_MESSAGE);
-}
-
-/**
- * Parse message response of failed request
- */
-export function parseMessage(response: Response): Promise<string> {
-  const DEFAULT_MESSAGE = translate('default_error_message');
-  return parseJSON(response)
-    .then(({ message }) => message)
+    .then(({ errors, message }) => message ?? errors.map((error: any) => error.msg).join('. '))
     .catch(() => DEFAULT_MESSAGE);
 }