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
7
# File 'lib/pliny/middleware/rescue_errors.rb', line 3

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

Instance Method Details

#call(env) ⇒ Object



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

def call(env)
  @app.call(env)
rescue Pliny::Errors::Error => e
  Pliny::Errors::Error.render(e)
rescue => e
  raise if @raise

  Pliny::ErrorReporters.notify(e, rack_env: env)
  Pliny::Errors::Error.render(Pliny::Errors::InternalServerError.new(@message))
end