Class: Pliny::Middleware::RescueErrors

Inherits:
Object
  • Object
show all
Defined in:
lib/pliny/middleware/rescue_errors.rb

Instance Method Summary collapse

Constructor Details

#initialize(app, options = {}) ⇒ RescueErrors

Returns a new instance of RescueErrors.



3
4
5
6
# File 'lib/pliny/middleware/rescue_errors.rb', line 3

def initialize(app, options = {})
  @app = app
  @raise = options[:raise]
end

Instance Method Details

#call(env) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/pliny/middleware/rescue_errors.rb', line 8

def call(env)
  @app.call(env)
rescue Pliny::Errors::Error => e
  # blank out this field so that the error is not picked up by Rollbar
  env["sinatra.error"] = nil

  Pliny::Errors::Error.render(e)
rescue Exception => e
  if @raise
    raise
  else
    dump_error(e, env)
    Pliny::Errors::Error.render(Pliny::Errors::InternalServerError.new)
  end
end