Exception: Mautic::ValidationError

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

Instance Attribute Summary

Attributes inherited from RequestError

#errors, #response

Instance Method Summary collapse

Constructor Details

#initialize(response, message = nil) ⇒ ValidationError



38
39
40
41
42
43
44
# File 'lib/mautic.rb', line 38

def initialize(response, message = nil)
  @response = response
  json_body = JSON.parse(response.body) rescue {}
  @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