Class: Grape::Middleware::Error

Inherits:
Base
  • Object
show all
Defined in:
lib/grape/middleware/error.rb

Constant Summary collapse

DEFAULT_OPTIONS =
{
  default_status: 500,
  default_message: '',
  format: :txt,
  rescue_all: false,
  rescue_grape_exceptions: false,
  rescue_subclasses: true,
  rescue_options: {
    backtrace: false,
    original_exception: false
  }.freeze
}.freeze

Instance Attribute Summary

Attributes inherited from Base

#app, #env, #options

Instance Method Summary collapse

Methods inherited from Base

#after, #before, #call, #content_type, #content_type_for, #content_types, #context, #mime_types, #query_params, #rack_request, #response

Methods included from DSL::Headers

#header

Constructor Details

#initialize(app, **options) ⇒ Error



19
20
21
22
# File 'lib/grape/middleware/error.rb', line 19

def initialize(app, **options)
  super
  self.class.include(options[:helpers]) if options[:helpers]
end

Instance Method Details

#call!(env) ⇒ Object



24
25
26
27
28
29
# File 'lib/grape/middleware/error.rb', line 24

def call!(env)
  @env = env
  error_response(catch(:error) { return @app.call(@env) })
rescue Exception => e # rubocop:disable Lint/RescueException
  run_rescue_handler(find_handler(e.class), e, @env[Grape::Env::API_ENDPOINT])
end