Module: JSONAPI::Utils::Support::Error

Included in:
Response::Support
Defined in:
lib/jsonapi/utils/support/error.rb

Constant Summary collapse

MEMBERS =
%i(title detail id code source links status meta).freeze

Class Method Summary collapse

Class Method Details

.sanitize(errors) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/jsonapi/utils/support/error.rb', line 9

def sanitize(errors)
  Array(errors).map do |error|
    MEMBERS.reduce({}) do |sum, key|
      value = error.try(key) || error.try(:[], key)
      if value.nil?
        sum
      else
        value = value.to_s if key == :code
        sum.merge(key => value)
      end
    end
  end
end