Module: Grape::ErrorFormatter::Base

Defined in:
lib/grape/error_formatter/base.rb

Constant Summary collapse

FORMATTERS =
{
  :json => Grape::ErrorFormatter::Json,
  :txt => Grape::ErrorFormatter::Txt,
  :xml => Grape::ErrorFormatter::Xml
}

Class Method Summary collapse

Class Method Details

.formatter_for(api_format, options = {}) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
# File 'lib/grape/error_formatter/base.rb', line 17

def formatter_for(api_format, options = {})
  spec = formatters(options)[api_format]
  case spec
  when nil
    lambda { |message, backtrace, options| message }
  when Symbol
    method(spec)
  else
    spec
  end
end

.formatters(options) ⇒ Object



13
14
15
# File 'lib/grape/error_formatter/base.rb', line 13

def formatters(options)
  FORMATTERS.merge(options[:error_formatters] || {})
end