blob: 8bdafb68c32e26c6a0fa5fb3bc057ac1b20f090e (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
import { observable, action } from 'mobx';
import Store from './lib/Store';
import Request from './lib/Request';
export default class GlobalErrorStore extends Store {
@observable error = null;
@observable response = {};
constructor(...args) {
super(...args);
Request.registerHook(this._handleRequests);
}
_handleRequests = action(async (request) => {
if (request.isError) {
this.error = request.error;
if (request.error.json) {
try {
this.response = await request.error.json();
} catch (error) {
this.response = {};
}
if (this.error.status === 401) {
window.ferdi.stores.app.authRequestFailed = true;
// this.actions.user.logout({ serverLogout: true });
}
}
} else {
window.ferdi.stores.app.authRequestFailed = false;
}
});
}
|