Track unhandled error counts in GA

This commit is contained in:
Gregory Schier
2017-07-17 15:37:24 -07:00
parent 207978bb23
commit e50dcdc579
3 changed files with 40 additions and 3 deletions

View File

@@ -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) {

View File

@@ -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);
}

View File

@@ -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: (
<div>
<p>The request failed due to an unhandled error:</p>
<code className="wide selectable">
<pre>{err.message}</pre>
</code>
</div>
)
});
}
// 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: (
<div>
<p>The request failed due to an unhandled error:</p>
<code className="wide selectable">
<pre>{err.message}</pre>
</code>
</div>
)
});
}
}