Exception: Mailgun::CommunicationError

Inherits:
Error
  • Object
show all
Defined in:
lib/mailgun/exceptions/exceptions.rb

Overview

Public: Class for managing communications (eg http) response errors Inherits from Mailgun::Error

Constant Summary collapse

NOCODE =

Public: fallback if there is no response code on the object

000

Instance Attribute Summary collapse

Attributes inherited from Error

#object

Instance Method Summary collapse

Constructor Details

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

Public: initialization of new error given a message and/or object

message - a String detailing the error response - a RestClient::Response object


43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/mailgun/exceptions/exceptions.rb', line 43

def initialize(message = nil, response = nil)
  @response = response
  @code = response.code || NOCODE

  begin
    api_message = JSON.parse(response.body)['message']
  rescue JSON::ParserError
    api_message = response.body
  rescue NoMethodError
    api_message = "Unknown API error"
  end

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

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

Instance Attribute Details

#codeObject (readonly)

Public: gets HTTP status code


33
34
35
# File 'lib/mailgun/exceptions/exceptions.rb', line 33

def code
  @code
end