Gestion erreur login
This commit is contained in:
parent
edcd4343eb
commit
6621e81e17
|
@ -2,6 +2,8 @@ import { call, put } from 'redux-saga/effects';
|
||||||
import { loginFailure, loginSuccess, logoutFailure, logoutSuccess } from '../actions/auth.actions';
|
import { loginFailure, loginSuccess, logoutFailure, logoutSuccess } from '../actions/auth.actions';
|
||||||
import { addMessage } from '../actions/message.actions';
|
import { addMessage } from '../actions/message.actions';
|
||||||
import { APIClient } from '../services/api-client.service.js';
|
import { APIClient } from '../services/api-client.service.js';
|
||||||
|
import { UnauthorizedError } from '../errors/unauthorized.error.js';
|
||||||
|
|
||||||
|
|
||||||
export function* loginSaga(action) {
|
export function* loginSaga(action) {
|
||||||
const client = new APIClient();
|
const client = new APIClient();
|
||||||
|
@ -9,10 +11,14 @@ export function* loginSaga(action) {
|
||||||
try {
|
try {
|
||||||
result = yield call(client.login, action.username, action.password);
|
result = yield call(client.login, action.username, action.password);
|
||||||
} catch(err) {
|
} catch(err) {
|
||||||
console.error(err);
|
if (err instanceof UnauthorizedError) {
|
||||||
|
yield put(addMessage('warning', "Identifiants invalides."));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
yield put(loginFailure(action.username, err));
|
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."));
|
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) {
|
if ('error' in result) {
|
||||||
|
|
Loading…
Reference in New Issue