aboutsummaryrefslogtreecommitdiffstats
path: root/src/stores/GlobalErrorStore.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/stores/GlobalErrorStore.js')
-rw-r--r--src/stores/GlobalErrorStore.js28
1 files changed, 28 insertions, 0 deletions
diff --git a/src/stores/GlobalErrorStore.js b/src/stores/GlobalErrorStore.js
new file mode 100644
index 000000000..f4b9d7838
--- /dev/null
+++ b/src/stores/GlobalErrorStore.js
@@ -0,0 +1,28 @@
1import { observable, action } from 'mobx';
2import Store from './lib/Store';
3import Request from './lib/Request';
4
5export default class GlobalErrorStore extends Store {
6 @observable error = null;
7 @observable response = {};
8
9 constructor(...args) {
10 super(...args);
11
12 Request.registerHook(this._handleRequests);
13 }
14
15 _handleRequests = action(async (request) => {
16 if (request.isError) {
17 this.error = request.error;
18
19 if (request.error.json) {
20 this.response = await request.error.json();
21
22 if (this.error.status === 401) {
23 this.actions.user.logout({ serverLogout: true });
24 }
25 }
26 }
27 });
28}