-
-
Save dgilperez/2585251 to your computer and use it in GitHub Desktop.
Trap Capybara Stack Trace
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### Show stack trace for 500 errors | |
### (adapted from https://gist.github.com/1079020) | |
# Given an application, yield to a block to handle exceptions | |
class ExceptionRaiserApp | |
def initialize(app) | |
@app = app | |
end | |
def call(env) | |
@app.call(env) | |
rescue => e | |
backtrace = [ "#{'*'*20} #{e.to_s} #{'*'*20}", | |
'', | |
e.message, | |
'', | |
Rails.backtrace_cleaner.clean(e.backtrace, :silent), | |
'', | |
'*'*80, | |
'' ].join("\n\t") | |
# log the backtrace | |
Rails.logger.error backtrace | |
# re-raise so capybara gets a 500 and knows what's up | |
raise e | |
end | |
end | |
Capybara.app = ExceptionRaiserApp.new(MyApp::Application) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment