gitlab-org--gitlab-foss/app/assets/javascripts/raven/raven_config.js

48 lines
1.0 KiB
JavaScript
Raw Normal View History

import Raven from 'raven-js';
const RavenConfig = {
init(options = {}) {
this.options = options;
this.configure();
this.bindRavenErrors();
if (this.options.currentUserId) this.setUser();
},
configure() {
Raven.config(this.options.sentryDsn, {
whitelistUrls: this.options.whitelistUrls,
environment: this.options.isProduction ? 'production' : 'development',
}).install();
},
setUser() {
Raven.setUserContext({
id: this.options.currentUserId,
});
},
bindRavenErrors() {
2017-04-15 07:29:46 -04:00
window.$(document).on('ajaxError.raven', this.handleRavenErrors);
},
handleRavenErrors(event, req, config, err) {
const error = err || req.statusText;
2017-04-15 07:29:46 -04:00
const responseText = req.responseText || 'Unknown response text';
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),
error,
event,
},
});
},
2017-04-14 16:09:16 -04:00
};
export default RavenConfig;