class Mailgun::CommunicationError

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

Constants

FORBIDDEN
NOCODE

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

Attributes

code[R]

Public: gets HTTP status code

Public Class Methods

new(message = nil, response = nil) click to toggle source

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

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

Calls superclass method Mailgun::Error::new
# File lib/mailgun/exceptions/exceptions.rb, line 44
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
  api_message = api_message + ' - Invalid Domain or API key' if api_message == FORBIDDEN

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

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