Class: Droonga::Plugins::Error::Adapter

Inherits:
Adapter
  • Object
show all
Defined in:
lib/droonga/plugins/error.rb

Instance Method Summary collapse

Methods inherited from Adapter

#adapt_input, id, input_message, output_message

Methods included from Droonga::Pluggable

#find_sub_classes, #options

Instance Method Details

#adapt_output(output_message) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/droonga/plugins/error.rb', line 27

def adapt_output(output_message)
  errors = output_message.body["errors"]
  if errors and !errors.empty?
    output_message.errors = errors

    status_codes = []
    errors.values.each do |error|
      status_codes << error["statusCode"]
    end
    status_codes = status_codes.uniq
    if status_codes.size == 1
      output_message.status_code = status_codes.first
    else
      output_message.status_code = ErrorMessages::InternalServerError::STATUS_CODE
    end

    output_message.body = errors.values.first["body"]
  else
    output_message.body.delete("errors")
  end
end