Exception: Mailgunner::Error

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

Direct Known Subclasses

ClientError, ServerError

Class Method Summary collapse

Class Method Details

.parse(response) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/mailgunner/errors.rb', line 5

def self.parse(response)
  exception_class = case response
    when Net::HTTPUnauthorized
      AuthenticationError
    when Net::HTTPClientError
      ClientError
    when Net::HTTPServerError
      ServerError
    else
      Error
    end

  message = if response['Content-Type']&.start_with?('application/json')
    JSON.parse(response.body)['message']
  end

  message ||= "HTTP #{response.code} response from Mailgun API"

  exception_class.new(message)
end