Class: Grape::Middleware::Error

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

Constant Summary

Constants inherited from Base

Base::TEXT_HTML

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, #mime_types, #response

Methods included from DSL::Headers

#header

Methods included from Helpers

#context

Constructor Details

#initialize(app, *options) ⇒ Error

Returns a new instance of Error.



27
28
29
30
# File 'lib/grape/middleware/error.rb', line 27

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

Instance Method Details

#call!(env) ⇒ Object



32
33
34
35
36
37
# File 'lib/grape/middleware/error.rb', line 32

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

#default_optionsObject



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/grape/middleware/error.rb', line 6

def default_options
  {
    default_status: 500, # default status returned on error
    default_message: '',
    format: :txt,
    helpers: nil,
    formatters: {},
    error_formatters: {},
    rescue_all: false, # true to rescue all exceptions
    rescue_grape_exceptions: false,
    rescue_subclasses: true, # rescue subclasses of exceptions listed
    rescue_options: {
      backtrace: false, # true to display backtrace, true to let Grape handle Grape::Exceptions
      original_exception: false # true to display exception
    },
    rescue_handlers: {}, # rescue handler blocks
    base_only_rescue_handlers: {}, # rescue handler blocks rescuing only the base class
    all_rescue_handler: nil # rescue handler block to rescue from all exceptions
  }
end