diff options
author | 2022-06-22 16:21:23 +0200 | |
---|---|---|
committer | 2022-06-23 17:50:07 +0530 | |
commit | caf43fc8d64c27a1aad4a5d6507313c513c1a447 (patch) | |
tree | c0a7bcb950cdf555b3e8a33a57e2241e7051861d /src/stores/GlobalErrorStore.js | |
parent | Workaroud for in-app Password Recovery (#342) (diff) | |
download | ferdium-app-caf43fc8d64c27a1aad4a5d6507313c513c1a447.tar.gz ferdium-app-caf43fc8d64c27a1aad4a5d6507313c513c1a447.tar.zst ferdium-app-caf43fc8d64c27a1aad4a5d6507313c513c1a447.zip |
chore: featureStore and GlobalErrorStore JS => TS
Diffstat (limited to 'src/stores/GlobalErrorStore.js')
-rw-r--r-- | src/stores/GlobalErrorStore.js | 87 |
1 files changed, 0 insertions, 87 deletions
diff --git a/src/stores/GlobalErrorStore.js b/src/stores/GlobalErrorStore.js deleted file mode 100644 index 356a6f298..000000000 --- a/src/stores/GlobalErrorStore.js +++ /dev/null | |||
@@ -1,87 +0,0 @@ | |||
1 | import { observable, action } from 'mobx'; | ||
2 | import Store from './lib/Store'; | ||
3 | import Request from './lib/Request'; | ||
4 | |||
5 | export default class GlobalErrorStore extends Store { | ||
6 | @observable error = null; | ||
7 | |||
8 | @observable messages = []; | ||
9 | |||
10 | @observable response = {}; | ||
11 | |||
12 | constructor(...args) { | ||
13 | super(...args); | ||
14 | |||
15 | window.addEventListener('error', (...errorArgs) => { | ||
16 | this._handleConsoleError.call(this, ['error', ...errorArgs]); | ||
17 | }); | ||
18 | |||
19 | const origConsoleError = console.error; | ||
20 | window.console.error = (...errorArgs) => { | ||
21 | this._handleConsoleError.call(this, ['error', ...errorArgs]); | ||
22 | origConsoleError.apply(this, errorArgs); | ||
23 | }; | ||
24 | |||
25 | const origConsoleLog = console.log; | ||
26 | window.console.log = (...logArgs) => { | ||
27 | this._handleConsoleError.call(this, ['log', ...logArgs]); | ||
28 | origConsoleLog.apply(this, logArgs); | ||
29 | }; | ||
30 | |||
31 | const origConsoleInfo = console.info; | ||
32 | window.console.info = (...infoArgs) => { | ||
33 | this._handleConsoleError.call(this, ['info', ...infoArgs]); | ||
34 | origConsoleInfo.apply(this, infoArgs); | ||
35 | }; | ||
36 | |||
37 | Request.registerHook(this._handleRequests); | ||
38 | } | ||
39 | |||
40 | _handleConsoleError(type, error, url, line) { | ||
41 | if (typeof type === 'object' && type.length > 0) { | ||
42 | this.messages.push({ | ||
43 | type: type[0], | ||
44 | info: type, | ||
45 | }); | ||
46 | } else { | ||
47 | this.messages.push({ | ||
48 | type, | ||
49 | error, | ||
50 | url, | ||
51 | line, | ||
52 | }); | ||
53 | } | ||
54 | } | ||
55 | |||
56 | _handleRequests = action(async request => { | ||
57 | if (request.isError) { | ||
58 | this.error = request.error; | ||
59 | |||
60 | if (request.error.json) { | ||
61 | try { | ||
62 | this.response = await request.error.json(); | ||
63 | } catch { | ||
64 | this.response = {}; | ||
65 | } | ||
66 | if (this.error.status === 401) { | ||
67 | window['ferdium'].stores.app.authRequestFailed = true; | ||
68 | // this.actions.user.logout({ serverLogout: true }); | ||
69 | } | ||
70 | } | ||
71 | |||
72 | this.messages.push({ | ||
73 | type: 'error', | ||
74 | request: { | ||
75 | result: request.result, | ||
76 | wasExecuted: request.wasExecuted, | ||
77 | method: request._method, | ||
78 | }, | ||
79 | error: this.error, | ||
80 | response: this.response, | ||
81 | server: window['ferdium'].stores.settings.app.server, | ||
82 | }); | ||
83 | } else { | ||
84 | window['ferdium'].stores.app.authRequestFailed = false; | ||
85 | } | ||
86 | }); | ||
87 | } | ||