Class: LHS::Problems::Errors

Inherits:
Base
  • Object
show all
Defined in:
lib/lhs/problems/errors.rb

Direct Known Subclasses

Nested::Errors

Instance Attribute Summary collapse

Attributes inherited from Base

#codes, #messages, #raw, #record

Instance Method Summary collapse

Methods inherited from Base

#[], #[]=, #add, #clear, #count, #each, #empty?, #get, #include?, #set, #size

Constructor Details

#initialize(response = nil, record = nil) ⇒ Errors

Returns a new instance of Errors.


8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/lhs/problems/errors.rb', line 8

def initialize(response = nil, record = nil)
  @raw = response.body if response
  @record = record
  @codes = {}.with_indifferent_access
  @messages = messages_from_response(response).with_indifferent_access
  @message = message_from_response(response)
  @status_code = response.code if response
rescue JSON::ParserError
  @messages = (messages || {}).with_indifferent_access
  @codes = (codes || {}).with_indifferent_access
  @message = 'parse error'
  add_error(@messages, 'body', 'parse error')
end

Instance Attribute Details

#messageObject (readonly)

Returns the value of attribute message


6
7
8
# File 'lib/lhs/problems/errors.rb', line 6

def message
  @message
end

#status_codeObject (readonly)

Returns the value of attribute status_code


6
7
8
# File 'lib/lhs/problems/errors.rb', line 6

def status_code
  @status_code
end