BetterErrors/better_errors

Rails Logger not receiving exception with AJAX requests

Opened this issue · 1 comments

I've seen other users mention that they're still running into issues with Ruby 2.5.x and Rails 5, and I'm in the same boat. However, the issue is that I'm not seeing logged errors.

better_errors (2.5.0) and binding_of_caller (0.8.0) are both fully updated so I started debugging the issue and found the issue to be a result of StackFrame injecting gem names into the backtrace, which is then silenced by Rail's default BacktraceCleaner setup.

Specifically:

https://github.com/BetterErrors/better_errors/blob/master/lib/better_errors/stack_frame.rb#L39

is silenced by:

https://github.com/rails/rails/blob/master/railties/lib/rails/backtrace_cleaner.rb#L7 and https://github.com/rails/rails/blob/master/railties/lib/rails/backtrace_cleaner.rb#L19

What's got me a little stumped is that the relevant functionality has been part of both BetterErrors and Rails for a very long time.

This is an issue with AJAX requests that fail. The BetterErrors prompt isn't shown because the HTML isn't displayed (no page reload, because AJAX). So I'm expecting that I can at least see the backtrace in the log. However, at present that's not happening.

I'll look into why the log is not getting the exception, it should.

When Better Errors handles an exception, it returns a 500 status code to the current request. Make sure your Javascript code that performs the ajax request is handling a failure. You should generally give the user some feedback in that case, and you can also show the error details in the console.

When developing, look at the server response in your browser developer tools. For example, the Network tab in Chrome. Better Errors sends a text response containing the backtrace in a human-readable format, which will cause a problem for the AJAX callback if that parses the response as JSON without looking to see if the response Content-Type is actually JSON.