Module: Grape::ErrorFormatter

Defined in:
lib/grape/error_formatter.rb,
lib/grape/error_formatter/txt.rb,
lib/grape/error_formatter/xml.rb,
lib/grape/error_formatter/base.rb,
lib/grape/error_formatter/json.rb

Defined Under Namespace

Modules: Base, Json, Txt, Xml

Constant Summary collapse

DEFAULTS =
{
  serializable_hash: Grape::ErrorFormatter::Json,
  json: Grape::ErrorFormatter::Json,
  jsonapi: Grape::ErrorFormatter::Json,
  txt: Grape::ErrorFormatter::Txt,
  xml: Grape::ErrorFormatter::Xml
}.freeze

Class Method Summary collapse

Class Method Details

.formatter_for(format, error_formatters = nil, default_error_formatter = nil) ⇒ Object



15
16
17
# File 'lib/grape/error_formatter.rb', line 15

def formatter_for(format, error_formatters = nil, default_error_formatter = nil)
  select_formatter(error_formatters, format) || default_error_formatter || DEFAULTS[:txt]
end

.select_formatter(error_formatters, format) ⇒ Object



19
20
21
# File 'lib/grape/error_formatter.rb', line 19

def select_formatter(error_formatters, format)
  error_formatters&.key?(format) ? error_formatters[format] : DEFAULTS[format]
end