lib/mailgun/client.rb in mailgun-ruby-1.2.8 vs lib/mailgun/client.rb in mailgun-ruby-1.2.9
- old
+ new
@@ -203,10 +203,19 @@
# Raises CommunicationError and stores response in it if present
#
# @param [StandardException] e upstream exception object
def communication_error(e)
- return CommunicationError.new(e.message, e.response) if e.respond_to? :response
+ if e.respond_to?(:response)
+ return case e.response.code
+ when Unauthorized::CODE
+ Unauthorized.new(e.message, e.response)
+ when BadRequest::CODE
+ BadRequest.new(e.message, e.response)
+ else
+ CommunicationError.new(e.message, e.response)
+ end
+ end
CommunicationError.new(e.message)
end
def perform_data_validation(working_domain, data)
message = data.respond_to?(:message) ? data.message : data