Gestion erreur login

This commit is contained in:
wpetit 2020-02-25 10:52:53 +01:00
parent edcd4343eb
commit 6621e81e17
1 changed files with 8 additions and 2 deletions

View File

@ -2,6 +2,8 @@ import { call, put } from 'redux-saga/effects';
import { loginFailure, loginSuccess, logoutFailure, logoutSuccess } from '../actions/auth.actions';
import { addMessage } from '../actions/message.actions';
import { APIClient } from '../services/api-client.service.js';
import { UnauthorizedError } from '../errors/unauthorized.error.js';
export function* loginSaga(action) {
const client = new APIClient();
@ -9,10 +11,14 @@ export function* loginSaga(action) {
try {
result = yield call(client.login, action.username, action.password);
} catch(err) {
console.error(err);
if (err instanceof UnauthorizedError) {
yield put(addMessage('warning', "Identifiants invalides."));
return;
}
yield put(loginFailure(action.username, err));
yield put(addMessage('danger', "Une erreur inconnue bloque le fonctionnement normal de l'application. Veuillez réessayer plus tard."));
return
return
}
if ('error' in result) {