Class: EffectiveTestBot::Middleware
- Inherits:
-
Object
- Object
- EffectiveTestBot::Middleware
- Defined in:
- lib/effective_test_bot/middleware.rb
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app) ⇒ Middleware
constructor
A new instance of Middleware.
- #save(exception) ⇒ Object
Constructor Details
#initialize(app) ⇒ Middleware
Returns a new instance of Middleware.
6 7 8 |
# File 'lib/effective_test_bot/middleware.rb', line 6 def initialize(app) @app = app end |
Instance Method Details
#call(env) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 |
# 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.}" end raise exception end end |
#save(exception) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/effective_test_bot/middleware.rb', line 24 def save(exception) lines = [exception.] + 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 |