2017-04-04 09:58:45 -04:00
|
|
|
import Raven from 'raven-js';
|
|
|
|
|
2017-04-13 12:17:41 -04:00
|
|
|
const RavenConfig = {
|
|
|
|
init(options = {}) {
|
2017-04-04 09:58:45 -04:00
|
|
|
this.options = options;
|
|
|
|
|
|
|
|
this.configure();
|
|
|
|
this.bindRavenErrors();
|
|
|
|
if (this.options.currentUserId) this.setUser();
|
2017-04-13 12:17:41 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
configure() {
|
2017-04-04 09:58:45 -04:00
|
|
|
Raven.config(this.options.sentryDsn, {
|
|
|
|
whitelistUrls: this.options.whitelistUrls,
|
|
|
|
environment: this.options.isProduction ? 'production' : 'development',
|
|
|
|
}).install();
|
2017-04-13 12:17:41 -04:00
|
|
|
},
|
2017-04-04 09:58:45 -04:00
|
|
|
|
2017-04-13 12:17:41 -04:00
|
|
|
setUser() {
|
2017-04-04 09:58:45 -04:00
|
|
|
Raven.setUserContext({
|
|
|
|
id: this.options.currentUserId,
|
|
|
|
});
|
2017-04-13 12:17:41 -04:00
|
|
|
},
|
2017-04-04 09:58:45 -04:00
|
|
|
|
2017-04-13 12:17:41 -04:00
|
|
|
bindRavenErrors() {
|
2017-04-15 07:29:46 -04:00
|
|
|
window.$(document).on('ajaxError.raven', this.handleRavenErrors);
|
2017-04-13 12:17:41 -04:00
|
|
|
},
|
2017-04-04 09:58:45 -04:00
|
|
|
|
2017-04-13 12:17:41 -04:00
|
|
|
handleRavenErrors(event, req, config, err) {
|
2017-04-04 09:58:45 -04:00
|
|
|
const error = err || req.statusText;
|
2017-04-15 07:29:46 -04:00
|
|
|
const responseText = req.responseText || 'Unknown response text';
|
2017-04-04 09:58:45 -04:00
|
|
|
|
|
|
|
Raven.captureMessage(error, {
|
|
|
|
extra: {
|
|
|
|
type: config.type,
|
|
|
|
url: config.url,
|
|
|
|
data: config.data,
|
|
|
|
status: req.status,
|
2017-04-15 07:29:46 -04:00
|
|
|
response: responseText.substring(0, 100),
|
2017-04-04 09:58:45 -04:00
|
|
|
error,
|
|
|
|
event,
|
|
|
|
},
|
|
|
|
});
|
2017-04-13 12:17:41 -04:00
|
|
|
},
|
2017-04-14 16:09:16 -04:00
|
|
|
};
|
2017-04-04 09:58:45 -04:00
|
|
|
|
|
|
|
export default RavenConfig;
|