diff options
Diffstat (limited to 'src/stores/GlobalErrorStore.js')
-rw-r--r-- | src/stores/GlobalErrorStore.js | 45 |
1 files changed, 34 insertions, 11 deletions
diff --git a/src/stores/GlobalErrorStore.js b/src/stores/GlobalErrorStore.js index 09c215c3e..0a3e62731 100644 --- a/src/stores/GlobalErrorStore.js +++ b/src/stores/GlobalErrorStore.js | |||
@@ -5,30 +5,52 @@ import Request from './lib/Request'; | |||
5 | export default class GlobalErrorStore extends Store { | 5 | export default class GlobalErrorStore extends Store { |
6 | @observable error = null; | 6 | @observable error = null; |
7 | 7 | ||
8 | @observable errors = []; | 8 | @observable messages = []; |
9 | 9 | ||
10 | @observable response = {}; | 10 | @observable response = {}; |
11 | 11 | ||
12 | constructor(...args) { | 12 | constructor(...args) { |
13 | super(...args); | 13 | super(...args); |
14 | 14 | ||
15 | window.onerror = this._handleConsoleError.bind(this); | 15 | window.onerror = (...errorArgs) => { |
16 | this._handleConsoleError.call(this, ['error', ...errorArgs]) | ||
17 | }; | ||
16 | 18 | ||
17 | const origConsoleError = console.error; | 19 | const origConsoleError = console.error; |
18 | console.error = (...errorArgs) => { | 20 | window.console.error = (...errorArgs) => { |
19 | this._handleConsoleError.call(this, errorArgs); | 21 | this._handleConsoleError.call(this, ['error', ...errorArgs]); |
20 | origConsoleError.apply(this, errorArgs); | 22 | origConsoleError.apply(this, errorArgs); |
21 | }; | 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 | }; | ||
22 | 36 | ||
23 | Request.registerHook(this._handleRequests); | 37 | Request.registerHook(this._handleRequests); |
24 | } | 38 | } |
25 | 39 | ||
26 | _handleConsoleError(error, url, line) { | 40 | _handleConsoleError(type, error, url, line) { |
27 | this.errors.push({ | 41 | if (typeof type === "object" && type.length && type.length >= 1) { |
28 | error, | 42 | this.messages.push({ |
29 | url, | 43 | type: type[0], |
30 | line, | 44 | info: type, |
31 | }); | 45 | }); |
46 | } else { | ||
47 | this.messages.push({ | ||
48 | type, | ||
49 | error, | ||
50 | url, | ||
51 | line, | ||
52 | }); | ||
53 | } | ||
32 | } | 54 | } |
33 | 55 | ||
34 | _handleRequests = action(async (request) => { | 56 | _handleRequests = action(async (request) => { |
@@ -47,7 +69,8 @@ export default class GlobalErrorStore extends Store { | |||
47 | } | 69 | } |
48 | } | 70 | } |
49 | 71 | ||
50 | this.errors.push({ | 72 | this.messages.push({ |
73 | type: 'error', | ||
51 | request: { | 74 | request: { |
52 | result: request.result, | 75 | result: request.result, |
53 | wasExecuted: request.wasExecuted, | 76 | wasExecuted: request.wasExecuted, |