diff --git a/assets/static/sentry.js b/assets/static/sentry.js new file mode 100644 index 000000000..0389b4761 --- /dev/null +++ b/assets/static/sentry.js @@ -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"); + } +} + +})(); diff --git a/assets/static/unsee.js b/assets/static/unsee.js index dbb6d77db..ecd2c0950 100644 --- a/assets/static/unsee.js +++ b/assets/static/unsee.js @@ -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( + '
' + + error.message + + '