Exception: Served::Serializers::JsonApi::Errors

Inherits:
Error show all
Includes:
Enumerable
Defined in:
lib/served/serializers/json_api/errors.rb

Overview

Wraps all error objects

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(response) ⇒ Errors

Returns a new instance of Errors.



11
12
13
14
15
16
17
# File 'lib/served/serializers/json_api/errors.rb', line 11

def initialize(response)
  errors_hash = JSON.parse(response.body)
  @errors = errors_hash['errors'].map { |error| Error.new(error) }
rescue JSON::ParserError
  @errors = [Error.new(status: response.code, title: 'Parsing Error',
                       detail: 'Service responded with an unparsable body')]
end

Instance Attribute Details

#errorsObject (readonly)

Returns the value of attribute errors.



9
10
11
# File 'lib/served/serializers/json_api/errors.rb', line 9

def errors
  @errors
end

Instance Method Details

#each(&block) ⇒ Object



19
20
21
# File 'lib/served/serializers/json_api/errors.rb', line 19

def each(&block)
  errors.each(&block)
end