Class: ChangeHealth::Response::Error

Inherits:
Object
  • Object
show all
Defined in:
lib/change_health/response/error.rb

Constant Summary collapse

SIMPLE_RETRY_CODES =
%w[
  42
  80
].freeze
NO_RESUBMIT_MESSAGES =
[
  'resubmission not allowed',
  'do not resubmit'
].freeze
DOWN_FIELD =
'Http Header'.freeze
DOWN_MESSAGE =
'Please review http headers for this API, please contact support if you are unsure how to resolve.'.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ Error

Returns a new instance of Error.



20
21
22
# File 'lib/change_health/response/error.rb', line 20

def initialize(data)
  @data = data
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



4
5
6
# File 'lib/change_health/response/error.rb', line 4

def data
  @data
end

Instance Method Details

#code_messageObject



32
33
34
# File 'lib/change_health/response/error.rb', line 32

def code_message
  "#{code}: #{description}" if code?
end

#field_messageObject



28
29
30
# File 'lib/change_health/response/error.rb', line 28

def field_message
  "#{field}: #{description}" if field?
end

#messageObject



24
25
26
# File 'lib/change_health/response/error.rb', line 24

def message
  field_message || code_message || @data.to_s
end

#represents_down?Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/change_health/response/error.rb', line 36

def represents_down?
  field == DOWN_FIELD && description == DOWN_MESSAGE
end

#retryable?Boolean

Returns:

  • (Boolean)


40
41
42
43
# File 'lib/change_health/response/error.rb', line 40

def retryable?
  represents_down? ||
    (code? && SIMPLE_RETRY_CODES.include?(code) && can_follow_up?)
end