Merge pull request #79 from cloudflare/raven-init

Better sentry javascript handling
This commit is contained in:
Łukasz Mierzwa
2017-04-26 07:50:36 -07:00
committed by GitHub
6 changed files with 70 additions and 31 deletions
+17
View File
@@ -0,0 +1,17 @@
var Sentry = (function() {
// init sentry client if sentry dsn is set
if ($("body").data("raven-dsn")) {
var dsn = $("body").data("raven-dsn").replace("\/", "/");
// raven itself can fail if invalid DSN is passed
try {
Raven.config(dsn, {
release: $("body").data("unsee-version")
}).install();
} catch (error) {
var msg = "Sentry error: " + error.message;
$("#raven-error").text(msg).removeClass("hidden");
}
}
})();
+18
View File
@@ -230,6 +230,8 @@ var Unsee = (function(params) {
$(document).ready(function() {
// wrap all inits so we can handle errors
try {
// init all elements using bootstrapSwitch
$('.toggle').bootstrapSwitch();
@@ -246,5 +248,21 @@ $(document).ready(function() {
setTimeout(function() {
Filters.SetFilters();
}, 100);
} catch (error) {
Raven.captureException(error);
if (window.console) {
console.error('Error: ' + error.stack);
}
// templates might not be loaded yet, make some html manually
$("#errors").html(
'<div class="jumbotron">' +
'<h1 class="text-center">' +
'Internal error <i class="fa fa-exclamation-circle text-danger"/>' +
'</h1>' +
'<div class="text-center"><p>' +
error.message +
'</p></div></div>'
).show();
}
});
-11
View File
@@ -281,14 +281,3 @@
</body>
</html>
{{ if .SentryDSN }}
<script type="application/javascript">
$(document).ready(function () {
var dsn = '{{ .SentryDSN }}'.replace('\/', '/');
Raven.config(dsn, {
release: {{ .Version }}
}).install();
});
</script>
{{ end }}
+6 -5
View File
@@ -20,7 +20,7 @@
</head>
<body class="dark">
<body class="dark" data-raven-dsn="{{ .SentryDSN }}" data-unsee-version="{{ .Version }}">
<nav class="navbar navbar-default navbar-fixed-top">
<div class="container">
@@ -134,10 +134,11 @@
</nav>
<div class="container-fluid" id="container">
<div id="errors"></div>
<div id="alerts" data-static-color-labels="{{ .StaticColorLabels }}">
<div class="grid-sizer"></div>
</div>
<div id="raven-error" class="alert alert-warning text-center hidden" role="alert"></div>
<div id="errors"></div>
<div id="alerts" data-static-color-labels="{{ .StaticColorLabels }}">
<div class="grid-sizer"></div>
</div>
</div>
<div class="flash" id="flash">
+2 -11
View File
@@ -1,3 +1,5 @@
<script type="text/javascript" src="{{ .WebPrefix }}static/sentry.js?_={{ .NowQ }}"></script>
<script type="text/javascript" src="{{ .WebPrefix }}static/jquery.typing-0.2.0.js"></script>
<script type="text/javascript" src="{{ .WebPrefix }}static/lru.js"></script>
@@ -15,14 +17,3 @@
<script type="text/javascript" src="{{ .WebPrefix }}static/querystring.js?_={{ .NowQ }}"></script>
<script type="text/javascript" src="{{ .WebPrefix }}static/ui.js?_={{ .NowQ }}"></script>
<script type="text/javascript" src="{{ .WebPrefix }}static/unsee.js?_={{ .NowQ }}"></script>
{{ if .SentryDSN }}
<script type="application/javascript">
$(document).ready(function () {
var dsn = '{{ .SentryDSN }}'.replace('\/', '/');
Raven.config(dsn, {
release: {{ .Version }}
}).install();
});
</script>
{{ end }}
+27 -4
View File
File diff suppressed because one or more lines are too long