Exception: Mailjet::CommunicationError

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

Direct Known Subclasses

BadRequest, Unauthorized

Constant Summary collapse

NOCODE =
000

Instance Attribute Summary collapse

Attributes inherited from Error

#object

Instance Method Summary collapse

Constructor Details

#initialize(message = nil, response = nil) ⇒ CommunicationError

Returns a new instance of CommunicationError.



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/mailjet/exception/errors.rb', line 49

def initialize(message = nil, response = nil)
  @response = response
  @code = if response.nil?
            NOCODE
          else
            response.response_status
          end

  api_message = begin
    if response.response_body.present?
      Yajl::Parser.parse(response.response_body)['ErrorMessage']
     else
      'Unauthorized'
    end
  rescue Yajl::ParseError
    response.response_body
  rescue NoMethodError
    "Unknown API error"
  rescue
    'Unknown API error'
  end

  message ||=  ''
  api_message ||= ''
  message = message + ': ' + api_message

  super(message, response)
rescue NoMethodError, JSON::ParserError
  @code = NOCODE
  super(message, response)
end

Instance Attribute Details

#codeObject (readonly)

Returns the value of attribute code.



45
46
47
# File 'lib/mailjet/exception/errors.rb', line 45

def code
  @code
end