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

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

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

#set_error_in_env(env, e) ⇒ Object

Sets the error in a predefined env key for use by the upstream CanonicalLogLine middleware.



24
25
26
# File 'lib/pliny/middleware/rescue_errors.rb', line 24

def set_error_in_env(env, e)
  env["pliny.error"] = e
end