From 58cda9cc7fb79ca9df6746de7f9662bc08dc156a Mon Sep 17 00:00:00 2001 From: Stefan Malzner Date: Fri, 13 Oct 2017 12:29:40 +0200 Subject: initial commit --- src/stores/GlobalErrorStore.js | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 src/stores/GlobalErrorStore.js (limited to 'src/stores/GlobalErrorStore.js') 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 @@ +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 }); + } + } + } + }); +} -- cgit v1.2.3-54-g00ecf