Class: Grape::Middleware::Error

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

Instance Attribute Summary

Attributes inherited from Base

#app, #env, #options

Instance Method Summary collapse

Methods inherited from Base

#after, #before, #call, #default_options, #initialize, #request, #response

Constructor Details

This class inherits a constructor from Grape::Middleware::Base

Instance Method Details

#call!(env) ⇒ Object



6
7
8
9
10
11
12
13
14
# File 'lib/grape/middleware/error.rb', line 6

def call!(env)
  @env = env
  result = catch :error do
    @app.call(@env)
  end
  
  result ||= {}
  result.is_a?(Hash) ? error_response(result) : result
end

#error_response(error = {}) ⇒ Object



16
17
18
# File 'lib/grape/middleware/error.rb', line 16

def error_response(error = {})
  Rack::Response.new([(error[:message] || options[:default_message])], error[:status] || 403, error[:headers] || {}).finish
end