Exception: Conexa::ValidationError

Inherits:
ConexaError show all
Defined in:
lib/conexa/errors.rb

Overview

Raised for an error body with no message key.

Every error response the published collection documents carries a message, so in practice this is reached only by an undocumented or malformed body. It used to render as the bare string "Conexa::ValidationError" and #to_h raised NoMethodError; both now degrade to something a caller can act on.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(response) ⇒ ValidationError

Returns a new instance of ValidationError.



105
106
107
108
109
110
111
112
113
114
# File 'lib/conexa/errors.rb', line 105

def initialize(response)
  @response = response
  @errors   = Array(response.is_a?(Hash) ? response['message'] : nil).filter_map do |msg|
    next unless msg.is_a?(Hash)

    ParamError.new(*msg.values_at('message', 'parameter_name', 'type', 'url'))
  end

  super(@errors.any? ? @errors.map(&:message).join(', ') : describe(response))
end

Instance Attribute Details

#errorsObject (readonly)

Returns the value of attribute errors.



103
104
105
# File 'lib/conexa/errors.rb', line 103

def errors
  @errors
end

#responseObject (readonly)

Returns the value of attribute response.



103
104
105
# File 'lib/conexa/errors.rb', line 103

def response
  @response
end

Instance Method Details

#to_hObject



116
117
118
# File 'lib/conexa/errors.rb', line 116

def to_h
  @errors.map(&:to_h)
end