From 769e553fae2abcb1559fd078ac2666a16482c9b5 Mon Sep 17 00:00:00 2001 From: vantezzen Date: Sun, 27 Oct 2019 20:15:33 +0100 Subject: Extend debug information --- src/stores/AppStore.js | 2 +- src/stores/GlobalErrorStore.js | 45 +++++++++++++++++++++++++++++++----------- 2 files changed, 35 insertions(+), 12 deletions(-) diff --git a/src/stores/AppStore.js b/src/stores/AppStore.js index 124c117b0..0756a05eb 100644 --- a/src/stores/AppStore.js +++ b/src/stores/AppStore.js @@ -253,7 +253,7 @@ export default class AppStore extends Store { hasCrashed: service.hasCrashed, isDarkModeEnabled: service.isDarkModeEnabled, })), - errors: this.stores.globalError.errors, + messages: this.stores.globalError.messages, workspaces: this.stores.workspaces.workspaces.map(workspace => ({ id: workspace.id, services: workspace.services })), windowSettings: readJsonSync(path.join(app.getPath('userData'), 'window-state.json')), settings, 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'; export default class GlobalErrorStore extends Store { @observable error = null; - @observable errors = []; + @observable messages = []; @observable response = {}; constructor(...args) { super(...args); - window.onerror = this._handleConsoleError.bind(this); + window.onerror = (...errorArgs) => { + this._handleConsoleError.call(this, ['error', ...errorArgs]) + }; const origConsoleError = console.error; - console.error = (...errorArgs) => { - this._handleConsoleError.call(this, errorArgs); + window.console.error = (...errorArgs) => { + this._handleConsoleError.call(this, ['error', ...errorArgs]); origConsoleError.apply(this, errorArgs); }; + + const origConsoleLog = console.log; + window.console.log = (...logArgs) => { + this._handleConsoleError.call(this, ['log', ...logArgs]); + origConsoleLog.apply(this, logArgs); + }; + + const origConsoleInfo = console.info; + window.console.info = (...infoArgs) => { + this._handleConsoleError.call(this, ['info', ...infoArgs]); + origConsoleInfo.apply(this, infoArgs); + }; Request.registerHook(this._handleRequests); } - _handleConsoleError(error, url, line) { - this.errors.push({ - error, - url, - line, - }); + _handleConsoleError(type, error, url, line) { + if (typeof type === "object" && type.length && type.length >= 1) { + this.messages.push({ + type: type[0], + info: type, + }); + } else { + this.messages.push({ + type, + error, + url, + line, + }); + } } _handleRequests = action(async (request) => { @@ -47,7 +69,8 @@ export default class GlobalErrorStore extends Store { } } - this.errors.push({ + this.messages.push({ + type: 'error', request: { result: request.result, wasExecuted: request.wasExecuted, -- cgit v1.2.3-70-g09d2