-
-
Save AdamT/7a70d6a30a9f2ffaa39b to your computer and use it in GitHub Desktop.
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
module MyApp | |
class Application < Rails::Application | |
if Rails.env == 'test' | |
require 'diagnostic' | |
config.middleware.use(MyApp::DiagnosticMiddleware) | |
end | |
end | |
end |
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
module MyApp | |
class DiagnosticMiddleware | |
FILENAME = 'diagnostic.txt' | |
def initialize(app) | |
@app = app | |
end | |
def call(env) | |
return @app.call(env) | |
rescue StandardError => e | |
trace = e.backtrace.select{ |l|l.start_with?(Rails.root.to_s) }.join("\n ") | |
msg = "#{e.class}\n#{e.message}\n#{trace}\n" | |
File.open(FILENAME, 'a') { |f| f.write msg } | |
raise e | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment