blob: f4b9d783838d4f2356c71a6d7b907dd2b8ff3309 (
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
|
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) {
this.response = await request.error.json();
if (this.error.status === 401) {
this.actions.user.logout({ serverLogout: true });
}
}
}
});
}
|