From e50dcdc579e005e6b3d44c497ed77c7303b4d91c Mon Sep 17 00:00:00 2001 From: Gregory Schier Date: Mon, 17 Jul 2017 15:37:24 -0700 Subject: [PATCH] Track unhandled error counts in GA --- app/analytics/index.js | 10 ++++++++++ app/ui/components/modals/index.js | 5 +++++ app/ui/containers/app.js | 28 +++++++++++++++++++++++++--- 3 files changed, 40 insertions(+), 3 deletions(-) diff --git a/app/analytics/index.js b/app/analytics/index.js index e1503056f7..30d1210df3 100644 --- a/app/analytics/index.js +++ b/app/analytics/index.js @@ -23,6 +23,16 @@ export async function init (accountId) { ipcRenderer.on('analytics-track-event', (_, args) => { trackEvent(...args); }); + + if (window) { + window.addEventListener('error', e => { + trackEvent('Error', 'Uncaught Error'); + }); + + window.addEventListener('unhandledrejection', e => { + trackEvent('Error', 'Uncaught Promise'); + }); + } } export function trackEvent (...args) { diff --git a/app/ui/components/modals/index.js b/app/ui/components/modals/index.js index 68626cf20f..896ef9d709 100644 --- a/app/ui/components/modals/index.js +++ b/app/ui/components/modals/index.js @@ -1,4 +1,5 @@ import PromptModal from './prompt-modal'; +import AlertModal from './alert-modal'; const modals = {}; @@ -14,6 +15,10 @@ export function showPrompt (config) { showModal(PromptModal, config); } +export function showAlert (config) { + showModal(AlertModal, config); +} + export function showModal (modalCls, ...args) { return _getModal(modalCls).show(...args); } diff --git a/app/ui/containers/app.js b/app/ui/containers/app.js index 3e108f2e14..7374a1be42 100644 --- a/app/ui/containers/app.js +++ b/app/ui/containers/app.js @@ -32,7 +32,7 @@ import * as mime from 'mime-types'; import * as path from 'path'; import * as render from '../../common/render'; import {getKeys} from '../../templating/utils'; -import {showPrompt} from '../components/modals/index'; +import {showAlert, showPrompt} from '../components/modals/index'; import {exportHar} from '../../common/har'; const KEY_ENTER = 13; @@ -440,8 +440,18 @@ class App extends PureComponent { } else { await models.response.create(responsePatch, bodyBuffer); } - } catch (e) { - // It's OK + } catch (err) { + showAlert({ + title: 'Unexpected Request Failure', + message: ( +
+

The request failed due to an unhandled error:

+ +
{err.message}
+
+
+ ) + }); } // Unset active response because we just made a new one @@ -473,6 +483,18 @@ class App extends PureComponent { } catch (err) { if (err.type === 'render') { showModal(RequestRenderErrorModal, {request, error: err}); + } else { + showAlert({ + title: 'Unexpected Request Failure', + message: ( +
+

The request failed due to an unhandled error:

+ +
{err.message}
+
+
+ ) + }); } }