Exception: Mautic::ValidationError

Inherits:
RequestError show all
Defined in:
lib/mautic.rb

Instance Attribute Summary

Attributes inherited from RequestError

#errors, #request_url, #response

Instance Method Summary collapse

Constructor Details

#initialize(response, message = nil) ⇒ ValidationError

Returns a new instance of ValidationError.



58
59
60
61
62
63
64
65
66
67
68
# File 'lib/mautic.rb', line 58

def initialize(response, message = nil)
  @response = response
  json_body = begin
                JSON.parse(response.body)
              rescue ParseError
                {}
              end
  @errors = Array(json_body['errors']).inject({}) { |mem, var| mem.merge!(var['details']); mem }
  message ||= @errors.collect { |field, msg| "#{field}: #{msg.join(', ')}" }.join('; ')
  super(response, message)
end