Sha256: 290a2540ab002cbeaec90d6fa876b8ad0b39105fbff692e8e69e1825a5f9f178

Contents?: true

Size: 790 Bytes

Versions: 5

Compression:

Stored size: 790 Bytes

Contents

# frozen_string_literal: true

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

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

      klass&.new(response)
    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

5 entries across 5 versions & 1 rubygems

Version Path
ivapi-1.9.0 lib/ivapi/error.rb
ivapi-1.8.0 lib/ivapi/error.rb
ivapi-1.7.0 lib/ivapi/error.rb
ivapi-1.6.1 lib/ivapi/error.rb
ivapi-1.6.0 lib/ivapi/error.rb