Skip to content

Commit 5718bf2

Browse files
author
Ives van Hoorne
committed
Sentry
1 parent 962dc78 commit 5718bf2

File tree

9 files changed

+119
-26
lines changed

9 files changed

+119
-26
lines changed

.eslintrc

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@
1212
"jest": true,
1313
"es6": true
1414
},
15+
"globals": {
16+
"Raven": true,
17+
"VERSION": true
18+
},
1519
"rules": {
1620
"react/jsx-filename-extension": 0,
1721
"react/sort-comp": 0,
@@ -25,4 +29,4 @@
2529
}
2630
}
2731
}
28-
}
32+
}

config/env.js

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
// Grab NODE_ENV and REACT_APP_* environment variables and prepare them to be
22
// injected into the application via DefinePlugin in Webpack configuration.
33

4-
var REACT_APP = /^REACT_APP_/i;
5-
var NODE_ENV = JSON.stringify(process.env.NODE_ENV || 'development');
4+
const REACT_APP = /^REACT_APP_/i;
5+
const NODE_ENV = JSON.stringify(process.env.NODE_ENV || 'development');
66

7-
module.exports = Object
8-
.keys(process.env)
7+
module.exports = Object.keys(process.env)
98
.filter(key => REACT_APP.test(key))
10-
.reduce((env, key) => {
11-
env['process.env.' + key] = JSON.stringify(process.env[key]);
12-
return env;
13-
}, {
14-
'process.env.NODE_ENV': NODE_ENV
15-
});
9+
.reduce(
10+
(env, key) => {
11+
env['process.env.' + key] = JSON.stringify(process.env[key]);
12+
return env;
13+
},
14+
{
15+
'process.env.NODE_ENV': NODE_ENV,
16+
}
17+
);

config/webpack.config.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ const path = require('path');
33
const paths = require('./paths');
44
const HtmlWebpackPlugin = require('html-webpack-plugin');
55
const CaseSensitivePathsPlugin = require('case-sensitive-paths-webpack-plugin');
6+
const childProcess = require('child_process');
67
const WatchMissingNodeModulesPlugin = require('../scripts/utils/WatchMissingNodeModulesPlugin');
78
const env = require('./env');
89

@@ -15,6 +16,15 @@ const __PROD__ = NODE_ENV === 'production'; // eslint-disable-line no-underscore
1516

1617
const babelConfig = __DEV__ ? babelDev : babelProd;
1718

19+
const COMMIT_COUNT = childProcess
20+
.execSync('git rev-list --count HEAD')
21+
.toString();
22+
23+
const COMMIT_HASH = childProcess
24+
.execSync('git rev-parse --short HEAD')
25+
.toString();
26+
const VERSION = `${COMMIT_COUNT}-${COMMIT_HASH}`;
27+
1828
const getOutput = () => __DEV__
1929
? {
2030
path: paths.appBuild,
@@ -182,6 +192,7 @@ const config = {
182192
// Makes some environment variables available to the JS code, for example:
183193
// if (process.env.NODE_ENV === 'development') { ... }. See `env.js`.
184194
new webpack.DefinePlugin(env),
195+
new webpack.DefinePlugin({ VERSION: JSON.stringify(VERSION) }),
185196
// Watcher doesn't work well if you mistype casing in a path so we use
186197
// a plugin that prints an error when you attempt to do this.
187198
// See https://github.com/facebookincubator/create-react-app/issues/240

src/app/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
ga('create', 'UA-89432508-1', 'auto');
3535
ga('send', 'pageview');
3636
</script>
37+
<script src="https://cdn.ravenjs.com/3.14.0/raven.min.js" crossorigin="anonymous"></script>
3738
</head>
3839

3940
<body style="margin: 0; padding: 0;">

src/app/index.js

Lines changed: 66 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,25 +11,79 @@ import './global.css';
1111
import './split-pane.css';
1212
import createStore from './store';
1313
import theme from '../common/theme';
14+
import logError from './utils/error';
15+
16+
if (process.env.NODE_ENV === 'production') {
17+
try {
18+
Raven.config('https://3943f94c73b44cf5bb2302a72d52e7b8@sentry.io/155188', {
19+
release: VERSION,
20+
ignoreErrors: [
21+
// Random plugins/extensions
22+
'top.GLOBALS',
23+
// See: http://blog.errorception.com/2012/03/tale-of-unfindable-js-error. html
24+
'originalCreateNotification',
25+
'canvas.contentDocument',
26+
'MyApp_RemoveAllHighlights',
27+
'http://tt.epicplay.com',
28+
"Can't find variable: ZiteReader",
29+
'jigsaw is not defined',
30+
'ComboSearch is not defined',
31+
'http://loading.retry.widdit.com/',
32+
'atomicFindClose',
33+
// Facebook borked
34+
'fb_xd_fragment',
35+
// ISP "optimizing" proxy - `Cache-Control: no-transform` seems to
36+
// reduce this. (thanks @acdha)
37+
// See http://stackoverflow.com/questions/4113268
38+
'bmi_SafeAddOnload',
39+
'EBCallBackMessageReceived',
40+
// See http://toolbar.conduit.com/Developer/HtmlAndGadget/Methods/JSInjection.aspx
41+
'conduitPage',
42+
],
43+
ignoreUrls: [
44+
// Facebook flakiness
45+
/graph\.facebook\.com/i,
46+
// Facebook blocked
47+
/connect\.facebook\.net\/en_US\/all\.js/i,
48+
// Woopra flakiness
49+
/eatdifferent\.com\.woopra-ns\.com/i,
50+
/static\.woopra\.com\/js\/woopra\.js/i,
51+
// Chrome extensions
52+
/extensions\//i,
53+
/^chrome:\/\//i,
54+
// Other plugins
55+
/127\.0\.0\.1:4001\/isrunning/i, // Cacaoweb
56+
/webappstoolbarba\.texthelp\.com\//i,
57+
/metrics\.itunes\.apple\.com\.edgesuite\.net\//i,
58+
],
59+
}).install();
60+
} catch (error) {
61+
console.error(error);
62+
}
63+
}
1464

1565
const rootEl = document.getElementById('root');
1666

1767
const history = createHistory();
1868

1969
const store = createStore(history);
2070
const renderApp = RootComponent => {
21-
render(
22-
<AppContainer>
23-
<ThemeProvider theme={theme}>
24-
<Provider store={store}>
25-
<ConnectedRouter history={history}>
26-
<RootComponent store={store} />
27-
</ConnectedRouter>
28-
</Provider>
29-
</ThemeProvider>
30-
</AppContainer>,
31-
rootEl
32-
);
71+
try {
72+
render(
73+
<AppContainer>
74+
<ThemeProvider theme={theme}>
75+
<Provider store={store}>
76+
<ConnectedRouter history={history}>
77+
<RootComponent store={store} />
78+
</ConnectedRouter>
79+
</Provider>
80+
</ThemeProvider>
81+
</AppContainer>,
82+
rootEl
83+
);
84+
} catch (e) {
85+
logError(e);
86+
}
3387
};
3488

3589
renderApp(App);

src/app/store/api/actions.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// @flow
22
import { values } from 'lodash';
33

4+
import sendError from 'app/utils/error';
45
import notificationActions from '../notifications/actions';
56
import apiRequest from '../services/api';
67
import type { BodyType } from '../services/api';
@@ -25,6 +26,10 @@ export function createAPIActions(prefix: string, suffix: string): APIActions {
2526
const getMessage = (error: Error) => {
2627
const response = error.response;
2728

29+
if (response.status >= 500) {
30+
sendError(error);
31+
}
32+
2833
if (response && response.data && response.data.errors) {
2934
const errors = values(response.data.errors)[0];
3035
if (Array.isArray(errors)) {

src/app/store/user/actions.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,12 @@ const getCurrentUser = () => async (dispatch: Function, getState: Function) => {
4040
doRequest(GET_CURRENT_USER_API, `users/current`)
4141
);
4242

43+
Raven.setUserContext({
44+
email: data.email,
45+
id: data.id,
46+
username: data.username,
47+
});
48+
4349
dispatch({ type: SET_CURRENT_USER, data });
4450
} catch (e) {
4551
dispatch(signOut());

src/app/utils/error.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
export default function logError(err, { level = 'error', service = '' } = {}) {
2+
// eslint-disable-next-line
3+
Raven.captureException(err, {
4+
level,
5+
extra: {
6+
service,
7+
},
8+
});
9+
/* eslint no-console:0 */
10+
window.console && console.error && console.error(err);
11+
}

src/sandbox/index.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,8 @@ async function compile(message) {
9696
host
9797
);
9898
} catch (e) {
99-
if (process.env.NODE_ENV === 'development') {
100-
console.error(e);
101-
}
99+
console.log('Error in sandbox:');
100+
console.error(e);
102101

103102
e.module = e.module || changedModule;
104103

0 commit comments

Comments
 (0)