Exception: Mailjet::ApiError

Inherits:
StandardError
  • Object
show all
Defined in:
lib/mailjet/exception/errors.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(code, body, request, url, params) ⇒ ApiError

Returns a new instance of ApiError.

Parameters:

  • code (Integer)

    HTTP response status code

  • body (String)

    JSON response body

  • request (Object)

    any request object

  • url (String)

    request URL

  • params (Hash)

    request headers and parameters



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/mailjet/exception/errors.rb', line 22

def initialize(code, body, request, url, params)
  @code = code
  @reason = begin
    resdec = JSON.parse(body)
    resdec['ErrorMessage']
  rescue JSON::ParserError
    body
  end

  if request.respond_to?(:options)
    request.options[:user] = '***'
    request.options[:password] = '***'
  end

  message = "error #{code} while sending #{request.inspect} to #{url} with #{params.inspect}"
  error_details = body.inspect
  hint = "Please see https://dev.mailjet.com/email/reference/overview/errors/ for more informations on error numbers."

  super("#{message}\n\n#{error_details}\n\n#{hint}\n\n")
end

Instance Attribute Details

#codeObject (readonly)

Returns the value of attribute code.



15
16
17
# File 'lib/mailjet/exception/errors.rb', line 15

def code
  @code
end

#reasonObject (readonly)

Returns the value of attribute reason.



15
16
17
# File 'lib/mailjet/exception/errors.rb', line 15

def reason
  @reason
end