Answer the question
In order to leave comments, you need to log in
Is error trapping implemented correctly?
Hello. Is the code for catching errors during registration correctly implemented, or should it be done differently? Here is the code of the function (If you do not use throw, then an error does not come in catch):
export let AuthUser = (userName, password) => async (dispatch) => {
try {
let token = await service.createRequestToken();
let validatedToken = await service.validateRequestToken(userName, password, token.request_token);
if (validatedToken.status_code === 3) {
throw 'Неправильное имя или пароль';
} else if (validatedToken.status_code === 8) {
throw 'Вы совершили слишком много попыток входа, попробуйте позже';
} else if (validatedToken.status_code === 9) {
throw 'Сервер недоступен, попробуйте позже';
} else if (validatedToken.status_code && validatedToken.status_code !== 1) {
throw 'Что-то пошло не так, попробуйте позже';
}
let sessionId = await service.createSessionId(validatedToken.request_token);
dispatch({type: 'SET_SESSION_ID', payload: sessionId});
let userData = await service.getAccountDetails(sessionId.session_id);
dispatch({type: 'SET_USER_DATA', payload: userData});
} catch (err) {
dispatch(stopSubmit("auth", {_error: err}));
}
}
Answer the question
In order to leave comments, you need to log in
In a good way, error texts should be sent by the server. Errors validating forms by keys.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question