Ajout saga gestion des actions de type '*_FAILURE'
This commit is contained in:
@ -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())
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user