Exception: Ivapi::Error

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

Direct Known Subclasses

BadRequest, Forbidden, Unauthorized

Class Method Summary collapse

Class Method Details

.from_response(response) ⇒ Object

Returns the appropriate Ivapi::Error sublcass based on status and response message.

response - The Hash of HTTP response.

Returns the Ivapi::Error.



11
12
13
14
15
16
17
18
19
20
21
# File 'lib/ivapi/error.rb', line 11

def self.from_response(response)
  status = response[:status].to_i

  klass = case status
  when 400 then Ivapi::BadRequest
  when 401 then Ivapi::Unauthorized
  when 403 then Ivapi::Forbidden
  end

  klass&.new(response)
end