diff options
author | Luke "Jared" Bennett <lbennett@gitlab.com> | 2017-04-04 14:58:45 +0100 |
---|---|---|
committer | Luke "Jared" Bennett <lbennett@gitlab.com> | 2017-04-13 17:18:15 +0100 |
commit | cfd3d0fd377c3438c6ce8bc2f20b11f86b43a785 (patch) | |
tree | aae1be8d8624e9bca4524dea1fdbdea26acb838f /app/assets/javascripts/raven | |
parent | ccca73d779ae0e22a86c9586fd52b15a8600b9f3 (diff) | |
download | gitlab-ce-cfd3d0fd377c3438c6ce8bc2f20b11f86b43a785.tar.gz |
[ci skip] Remove loadscript class in favour of backend conditional
Diffstat (limited to 'app/assets/javascripts/raven')
-rw-r--r-- | app/assets/javascripts/raven/index.js | 10 | ||||
-rw-r--r-- | app/assets/javascripts/raven/raven_config.js | 46 |
2 files changed, 56 insertions, 0 deletions
diff --git a/app/assets/javascripts/raven/index.js b/app/assets/javascripts/raven/index.js new file mode 100644 index 00000000000..6cc81248e6b --- /dev/null +++ b/app/assets/javascripts/raven/index.js @@ -0,0 +1,10 @@ +import RavenConfig from './raven_config'; + +RavenConfig.init({ + sentryDsn: gon.sentry_dsn, + currentUserId: gon.current_user_id, + whitelistUrls: [gon.gitlab_url], + isProduction: gon.is_production, +}); + +export default RavenConfig; diff --git a/app/assets/javascripts/raven/raven_config.js b/app/assets/javascripts/raven/raven_config.js new file mode 100644 index 00000000000..5510dd2752d --- /dev/null +++ b/app/assets/javascripts/raven/raven_config.js @@ -0,0 +1,46 @@ +import Raven from 'raven-js'; + +class RavenConfig { + static init(options = {}) { + this.options = options; + + this.configure(); + this.bindRavenErrors(); + if (this.options.currentUserId) this.setUser(); + } + + static configure() { + Raven.config(this.options.sentryDsn, { + whitelistUrls: this.options.whitelistUrls, + environment: this.options.isProduction ? 'production' : 'development', + }).install(); + } + + static setUser() { + Raven.setUserContext({ + id: this.options.currentUserId, + }); + } + + static bindRavenErrors() { + $(document).on('ajaxError.raven', this.handleRavenErrors); + } + + static handleRavenErrors(event, req, config, err) { + const error = err || req.statusText; + + Raven.captureMessage(error, { + extra: { + type: config.type, + url: config.url, + data: config.data, + status: req.status, + response: req.responseText.substring(0, 100), + error, + event, + }, + }); + } +} + +export default RavenConfig; |