Sha256: 61fed3da16c37e8ef18d8291ad5a5391c9e1032181c5313aba7be8134088bc39

Contents?: true

Size: 1.22 KB

Versions: 10

Compression:

Stored size: 1.22 KB

Contents

class Zephyr
  # Raised when a request fails due to either a timeout or when the expected
  # response code does not match the actual response code.
  class FailedRequest < StandardError
    attr_reader :method, :uri, :expected_code, :timeout, :response

    # The following options are required:
    #
    # method        - The HTTP method used for the request.
    # uri           - The uri of the request.
    # expected_code - The expected response code for the request.
    # timeout       - The timeout (in milliseconds) for the request.
    # response      - The response.
    def initialize(options)
      @method        = options[:method].to_s.upcase
      @uri           = options[:uri]
      @expected_code = options[:expected_code]
      @timeout       = options[:timeout]
      @response      = options[:response]

      super "#{@method} #{@uri} - #{error_message}"
    end

    # Returns whether the request timed out.
    def timed_out?
      @response.timed_out? || @response.code == 0
    end

    private
      def error_message
        if timed_out?
          "Response exceeded #{@timeout}ms."
        else
          "Expected #{@expected_code} from the server but received #{@response.code}."
        end
      end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
zephyr-1.2.2 lib/zephyr/failed_request.rb
zephyr-1.2.1 lib/zephyr/failed_request.rb
zephyr-1.2.0 lib/zephyr/failed_request.rb
zephyr-1.1.9 lib/zephyr/failed_request.rb
zephyr-1.1.8 lib/zephyr/failed_request.rb
zephyr-1.1.7 lib/zephyr/failed_request.rb
zephyr-1.1.6 lib/zephyr/failed_request.rb
zephyr-1.1.5 lib/zephyr/failed_request.rb
zephyr-1.1.3 lib/zephyr/failed_request.rb
zephyr-1.1.2 lib/zephyr/failed_request.rb