We use the Rollbar JS library to report exceptions to our Rollbar account. Unfortunately we don’t have any report of exceptions happening in our StimulusJS controllers.
When I add a try {} catch (e) {} block on my controller code, it works fine and I can report the exception with Rollbar.error(). But we have no event sent on uncatched JS exceptions, unlike exceptions happening from our vanilla JS code.
Rollbar provides a guide for Node.JS, AngularJS and React:
I have 2 questions:
(specific to Rollbar) Why are these exceptions not sent to Rollbar, unlike the ones from our vanilla JS code?
Is there any way to write custom code on any exception happening from a StimulusJS controller?
I’m having the same problem with Sentry. It seems like it would make sense to enable adding additional global handlers that can deal with these errors, as well. Should this only be a single handler? An array of handlers? Obviously a single handler introduce less complexity (and if need be that handler could encapsulate multiple handlers). If multiple handlers, should it expose an array or set directly or protect the internal data structure via add/remove methods?
I’m happy to put together a pull request for this. At the moment I’m leaning towards just a single handler as I don’t see this being a dynamic property - I imagine it’ll just be set once globally and left alone after that.
Feel free to weigh in, I’d love to hear anyone’s thoughts!
@mhulet - In the interim, I’ve just overridden the application’s error handler and added in Sentry’s manual handler, which I imagine could be done with Rollbar, as well. Note, this is taken from a Rails 6 app using their default Stimulus configuration.
How do I get application running environment name inside javascript/controllers/application.js? I want to ignore error being reported from development and test environment.
I have added environment name <body data-environment="<%= Rails.env %>"> in application.html.erb file but unable to get that in javascript/controllers/application.js.