Sha256: 09f1d39de26b992653144eba2170e2b68a5c4e91751e0fbe0d2282c9ebb0040e

Contents?: true

Size: 1.68 KB

Versions: 15

Compression:

Stored size: 1.68 KB

Contents

# frozen_string_literal: true

module PriceHubble
  # Generic entity exception class.
  class EntityError < StandardError
  end

  # Generic request/response exception class.
  class RequestError < StandardError
    attr_reader :response

    # Create a new instance of the error.
    #
    # @param message [String] the error message
    # @param response [Faraday::Response] the response
    def initialize(message = nil, response = nil)
      @response = response
      message ||= response.body.message if response.body.respond_to? :message

      super(message)
    end
  end

  # Raised when the authentication request failed.
  class AuthenticationError < RequestError; end

  # Raised when an entity was not found while searching/getting.
  class EntityNotFound < EntityError
    attr_reader :entity, :criteria

    # Create a new instance of the error.
    #
    # @param message [String] the error message
    # @param entity [PriceHubble::BaseEntity] the entity which was not found
    # @param criteria [Hash{Symbol => Mixed}] the search/find criteria
    def initialize(message = nil, entity = nil, criteria = {})
      @entity = entity
      @criteria = criteria
      message ||= "Couldn't find #{entity} with #{criteria.inspect}"

      super(message)
    end
  end

  # Raised when the record is invalid, due to a response.
  class EntityInvalid < EntityError
    attr_reader :entity

    # Create a new instance of the error.
    #
    # @param message [String] the error message
    # @param entity [PriceHubble::BaseEntity] the entity which was invalid
    def initialize(message = nil, entity = nil)
      @entity = entity
      message ||= "Invalid #{entity}"

      super(message)
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
pricehubble-1.3.0 lib/price_hubble/errors.rb
pricehubble-1.2.5 lib/price_hubble/errors.rb
pricehubble-1.2.4 lib/price_hubble/errors.rb
pricehubble-1.2.3 lib/price_hubble/errors.rb
pricehubble-1.2.2 lib/price_hubble/errors.rb
pricehubble-1.2.1 lib/price_hubble/errors.rb
pricehubble-1.2.0 lib/price_hubble/errors.rb
pricehubble-1.1.0 lib/pricehubble/errors.rb
pricehubble-1.0.0 lib/pricehubble/errors.rb
pricehubble-0.4.2 lib/pricehubble/errors.rb
pricehubble-0.4.1 lib/pricehubble/errors.rb
pricehubble-0.4.0 lib/pricehubble/errors.rb
pricehubble-0.3.0 lib/pricehubble/errors.rb
pricehubble-0.2.0 lib/pricehubble/errors.rb
pricehubble-0.1.0 lib/pricehubble/errors.rb