Class: TDiary::Rack::ErrorHandler
- Inherits:
-
Object
- Object
- TDiary::Rack::ErrorHandler
- Defined in:
- lib/tdiary/rack/error_handler.rb
Overview
class ErrorHandler catches exceptions leaked from the downstream app, reports the class, message and backtrace to rack.errors, and replaces the response with a plain 500 that does not expose the details to the client.
Class Method Summary collapse
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app) ⇒ ErrorHandler
constructor
A new instance of ErrorHandler.
Constructor Details
#initialize(app) ⇒ ErrorHandler
Returns a new instance of ErrorHandler.
11 12 13 |
# File 'lib/tdiary/rack/error_handler.rb', line 11 def initialize( app ) @app = app end |
Class Method Details
.report(errors, e) ⇒ Object
22 23 24 25 26 |
# File 'lib/tdiary/rack/error_handler.rb', line 22 def self.report( errors, e ) errors.puts "#{e.class}: #{e.}" ( e.backtrace || [] ).each {|line| errors.puts "\t#{line}" } errors.flush end |
Instance Method Details
#call(env) ⇒ Object
15 16 17 18 19 20 |
# File 'lib/tdiary/rack/error_handler.rb', line 15 def call( env ) @app.call( env ) rescue Exception => e self.class.report( env['rack.errors'], e ) [500, { 'content-type' => 'text/plain' }, ["500 Internal Server Error\n"]] end |