Class: Ixtlan::Errors::Rack
- Inherits:
-
Object
- Object
- Ixtlan::Errors::Rack
- Defined in:
- lib/ixtlan/errors/rack.rb
Constant Summary collapse
- DEFAULT_MAP =
{}
Instance Method Summary collapse
- #call(env) ⇒ Object
- #dump_to_console ⇒ Object
-
#initialize(app, dumper, map = {}) ⇒ Rack
constructor
A new instance of Rack.
Constructor Details
#initialize(app, dumper, map = {}) ⇒ Rack
Returns a new instance of Rack.
48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/ixtlan/errors/rack.rb', line 48 def initialize(app, dumper, map = {} ) @app = app @dumper = dumper @map = {} DEFAULT_MAP.each do |status, list| list.each { |exp| @map[ exp ] = status } end map.each do |status, list| list.each { |exp| @map[ exp ] = status } end end |
Instance Method Details
#call(env) ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/ixtlan/errors/rack.rb', line 64 def call(env) begin @app.call(env) rescue Exception => e status = @map[ e.class ] || 500 if status >= 500 req = ::Rack::Request.new env @dumper.dump( e, env, {}, req.session, req.params ) end warn "[Ixtlan::Errors] #{e.class}: #{e.}" if dump_to_console # dump to console and raise exception to let rack create # an error page warn "\t" + e.backtrace.join( "\n\t" ) if e.backtrace && status >= 500 raise e else [ status, {'Content-Type' => 'text/plain'}, [ ::Rack::Utils::HTTP_STATUS_CODES[ status ] ] ] end end end |
#dump_to_console ⇒ Object
60 61 62 |
# File 'lib/ixtlan/errors/rack.rb', line 60 def dump_to_console @dumper.keep_dumps == 0 end |