Exception: Gbizinfo::Api::Error

Inherits:
StandardError
  • Object
show all
Defined in:
lib/gbizinfo/api/error.rb

Direct Known Subclasses

ClientError, ServerError

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(response = nil) ⇒ Error

Returns a new instance of Error.



20
21
22
23
# File 'lib/gbizinfo/api/error.rb', line 20

def initialize(response = nil)
  @response = response
  super(build_error_message)
end

Class Method Details

.from_response(response) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/gbizinfo/api/error.rb', line 4

def self.from_response(response)
  klass =
    case response.status
    when 400      then Gbizinfo::Api::BadRequest
    when 401      then Gbizinfo::Api::Unauthorized
    when 403      then Gbizinfo::Api::Forbidden
    when 404      then Gbizinfo::Api::NotFound
    when 400..499 then Gbizinfo::Api::ClientError
    when 500      then Gbizinfo::Api::InternalServerError
    when 502      then Gbizinfo::Api::BadGateway
    when 503      then Gbizinfo::Api::ServiceUnavailable
    when 500..599 then Gbizinfo::Api::ServerError
    end
  klass&.new(response)
end