Sha256: 814ab5b4fbb10805c094a874e93c9de5943860766d67b8b5e120fb958b06e096

Contents?: true

Size: 778 Bytes

Versions: 12

Compression:

Stored size: 778 Bytes

Contents

require 'faraday'

require 'saddle/errors'



module Saddle
  module Middleware

    # Public: Enforces a ruby timeout on the request and throws one consistent
    # exception for all classes of timeout, internal or from faraday.
    # :timeout must be present in the request or client options
    class RubyTimeout < Faraday::Middleware

      def call(env)
        timeout = env[:request][:timeout] # nil or 0 means no timeout
        Timeout.timeout(timeout, Saddle::TimeoutError) do
          @app.call(env)
        end
      # It is possible that faraday will catch the timeout first and throw
      # this exception, rethrow as a class derived from standard error.
      rescue Faraday::Error::TimeoutError
        raise Saddle::TimeoutError
      end

    end

  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
saddle-0.0.27 lib/saddle/middleware/ruby_timeout.rb
saddle-0.0.26 lib/saddle/middleware/ruby_timeout.rb
saddle-0.0.25 lib/saddle/middleware/ruby_timeout.rb
saddle-0.0.23 lib/saddle/middleware/ruby_timeout.rb
saddle-0.0.22 lib/saddle/middleware/ruby_timeout.rb
saddle-0.0.21 lib/saddle/middleware/ruby_timeout.rb
saddle-0.0.19 lib/saddle/middleware/ruby_timeout.rb
saddle-0.0.18 lib/saddle/middleware/ruby_timeout.rb
saddle-0.0.17 lib/saddle/middleware/ruby_timeout.rb
saddle-0.0.16 lib/saddle/middleware/ruby_timeout.rb
saddle-0.0.15 lib/saddle/middleware/ruby_timeout.rb
saddle-0.0.14 lib/saddle/middleware/ruby_timeout.rb