class Pliny::Middleware::RescueErrors

Public Class Methods

new(app, options = {}) click to toggle source
# File lib/pliny/middleware/rescue_errors.rb, line 3
def initialize(app, options = {})
  @app = app
  @raise = options[:raise]
  @message = options[:message]
end

Public Instance Methods

call(env) click to toggle source
# 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) click to toggle source

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

# File lib/pliny/middleware/rescue_errors.rb, line 24
def set_error_in_env(env, e)
  env["pliny.error"] = e
end