Ensure raven-js is loaded first and works if enabled

This moves raven init into a dedicated file where it's configured on load, we no longer load it on /help, but there's only css there so there wasn't anything that could fail anyway. We will also now fail in the most visible way if the value passed to raven is invalid (as in invalid syntax)
This commit is contained in:
Łukasz Mierzwa
2017-04-25 22:32:32 -07:00
parent 1e9d1edc14
commit 45ba69cf76
5 changed files with 51 additions and 30 deletions

17
assets/static/sentry.js Normal file
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");
}
}
})();

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 }}

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">

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 }}

File diff suppressed because one or more lines are too long