Exception: Mautic::RequestError

Inherits:
StandardError
  • Object
show all
Defined in:
lib/mautic.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(response, message = nil) ⇒ RequestError

Returns a new instance of RequestError.



15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/mautic.rb', line 15

def initialize(response, message = nil)
  @errors ||= []
  @response = response
  json_body = JSON.parse(response.body) rescue {}
  message ||= Array(json_body['errors']).collect do |error|
    msg = error['code'].to_s
    msg << " (#{error['type']}):" if error['type']
    msg << " #{error['message']}"
    @errors << error['message']
    msg
  end.join(', ')

  super(message)
end

Instance Attribute Details

#errorsObject (readonly)

Returns the value of attribute errors.



13
14
15
# File 'lib/mautic.rb', line 13

def errors
  @errors
end

#responseObject (readonly)

Returns the value of attribute response.



13
14
15
# File 'lib/mautic.rb', line 13

def response
  @response
end