class EffectiveTestBot::Middleware
Public Class Methods
new(app)
click to toggle source
# File lib/effective_test_bot/middleware.rb, line 6 def initialize(app) @app = app end
Public Instance Methods
call(env)
click to toggle source
# File lib/effective_test_bot/middleware.rb, line 10 def call(env) begin @app.call(env) rescue Exception => exception begin save(exception) rescue => e puts "TestBotError: An error occurred while attempting to save a rails server exception: #{e.message}" end raise exception end end
save(exception)
click to toggle source
# File lib/effective_test_bot/middleware.rb, line 24 def save(exception) lines = [exception.message] + exception.backtrace.first(EffectiveTestBot&.backtrace_lines || 10) dir = File.join(Dir.pwd, 'tmp', 'test_bot') file = File.join(dir, 'exception.txt') Dir.mkdir(dir) unless File.exist?(dir) File.delete(file) if File.exist?(file) File.open(file, 'w') do |file| file.write "================== Start server exception ==================\n" lines.each { |line| file.write(line); file.write("\n") } file.write "=================== End server exception ===================\n" end end