Class: DocverterServer::ErrorHandler

Inherits:
Object
  • Object
show all
Defined in:
lib/docverter-server/error_handler.rb

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ ErrorHandler

Returns a new instance of ErrorHandler.



5
6
7
# File 'lib/docverter-server/error_handler.rb', line 5

def initialize(app)
  @app = app
end

Instance Method Details

#call(env) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/docverter-server/error_handler.rb', line 9

def call(env)
  begin
    @app.call env
  rescue => ex
    env['rack.errors'].puts ex
    env['rack.errors'].puts ex.backtrace.join("\n")
    env['rack.errors'].flush

    hash = { :error => ex.to_s }

    [500, {'Content-Type' => 'application/json'}, [MultiJson.dump(hash)]]
  end
end