Class: Adcloud::ExceptionRaiser

Inherits:
Object
  • Object
show all
Defined in:
lib/adcloud/exception_raiser.rb

Instance Method Summary collapse

Constructor Details

#initialize(response) ⇒ ExceptionRaiser

Returns a new instance of ExceptionRaiser.



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/adcloud/exception_raiser.rb', line 5

def initialize(response)
  Adcloud.logger.warn { "API Exception #{response.inspect}" }

  case response.status
  when 400
    raise Adcloud::BadRequestError.new(response)
  when 401
    raise Adcloud::Unauthorized.new(response)
  when 404
    raise Adcloud::NotFoundError.new(response)
  when 500
    raise Adcloud::ServerError.new(response)
  else
    raise StandardError.new("Could not handle status #{response.status}")
  end
end