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
-
#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 59 |
# File 'lib/ixtlan/errors/rack.rb', line 48 def initialize(app, dumper, map = {} ) @app = app @dumper = dumper @dump_to_console = dumper.keep_dumps == 0 @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
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/ixtlan/errors/rack.rb', line 61 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 if @dump_to_console warn "[Ixtlan::Errors] #{e.class}: #{e.}" warn "\t" + e.backtrace.join( "\n\t" ) if e.backtrace && status >= 500 end [ status, {'Content-Type' => 'text/plain'}, [ ::Rack::Utils::HTTP_STATUS_CODES[ status ] ] ] end end |