Sha256: 53965d1e9de2b5359e06729a9688f36aa0e5c5e1c6e8049ecb7c8f206e60cce6

Contents?: true

Size: 898 Bytes

Versions: 6

Compression:

Stored size: 898 Bytes

Contents

module Ivapi
  class Error < StandardError
    # Returns the appropriate Ivapi::Error sublcass based
    # on status and response message.
    #
    # response - The Hash of HTTP response.
    #
    # Returns the Ivapi::Error.
    def self.from_response(response)
      status  = response[:status].to_i
      body    = response[:body].to_s
      headers = response[:response_headers]

      if klass = case status
                 when 400 then Ivapi::BadRequest
                 when 401 then Ivapi::Unauthorized
                 when 403 then Ivapi::Forbidden
                 end
        klass.new(response)
      end
    end
  end

  # Raised when iv.lt returns a 400 HTTP status code
  class BadRequest < Error; end

  # Raised when iv.lt returns a 401 HTTP status code
  class Unauthorized < Error; end

  # Raised when iv.lt returns a 403 HTTP status code
  class Forbidden < Error; end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
ivapi-1.1.5 lib/ivapi/error.rb
ivapi-1.1.4 lib/ivapi/error.rb
ivapi-1.1.3 lib/ivapi/error.rb
ivapi-1.1.2 lib/ivapi/error.rb
ivapi-1.1.1 lib/ivapi/error.rb
ivapi-1.1.0 lib/ivapi/error.rb