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