Browse Source

SONAR-19967 Fix error message parsing when updating user

tags/10.2.0.77647
guillaume-peoch-sonarsource 10 months ago
parent
commit
e6c3fd761f

+ 2
- 2
server/sonar-web/src/main/js/apps/users/components/UserForm.tsx View 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);
}
};


+ 1
- 11
server/sonar-web/src/main/js/helpers/request.ts View 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);
}


Loading…
Cancel
Save