Ajout saga gestion des actions de type '*_FAILURE'

This commit is contained in:
2020-02-25 10:46:17 +01:00
parent 8ba45f84cb
commit edcd4343eb
5 changed files with 31 additions and 1 deletions

View File

@ -1,7 +1,10 @@
import { UnauthorizedError } from '../errors/unauthorized.error.js';
export const UnauthorizedStatusCode = 401;
export class APIClient {
constructor(baseURL = 'http://localhost:8001/api/v1') {
this.baseURL = baseURL;
this.baseURL = baseURL;
this.login = this.login.bind(this);
this.logout = this.logout.bind(this);
this.me = this.me.bind(this);
@ -47,6 +50,12 @@ export class APIClient {
credentials: 'include',
body: JSON.stringify(body),
})
.then(res => {
if (res.status === UnauthorizedStatusCode) {
throw new UnauthorizedError();
}
return res;
})
.then(res => res.json())
}