Sha256: 11a4924c79f8450ba1963f5e77e716e1ad8a3d11149be90ed340ee931ecf3956

Contents?: true

Size: 783 Bytes

Versions: 20

Compression:

Stored size: 783 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][:hard_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

20 entries across 20 versions & 1 rubygems

Version Path
saddle-0.0.53 lib/saddle/middleware/ruby_timeout.rb
saddle-0.0.51 lib/saddle/middleware/ruby_timeout.rb
saddle-0.0.50 lib/saddle/middleware/ruby_timeout.rb
saddle-0.0.49 lib/saddle/middleware/ruby_timeout.rb
saddle-0.0.48 lib/saddle/middleware/ruby_timeout.rb
saddle-0.0.46 lib/saddle/middleware/ruby_timeout.rb
saddle-0.0.45 lib/saddle/middleware/ruby_timeout.rb
saddle-0.0.44 lib/saddle/middleware/ruby_timeout.rb
saddle-0.0.43 lib/saddle/middleware/ruby_timeout.rb
saddle-0.0.42 lib/saddle/middleware/ruby_timeout.rb
saddle-0.0.41 lib/saddle/middleware/ruby_timeout.rb
saddle-0.0.38 lib/saddle/middleware/ruby_timeout.rb
saddle-0.0.37 lib/saddle/middleware/ruby_timeout.rb
saddle-0.0.36 lib/saddle/middleware/ruby_timeout.rb
saddle-0.0.35 lib/saddle/middleware/ruby_timeout.rb
saddle-0.0.34 lib/saddle/middleware/ruby_timeout.rb
saddle-0.0.33 lib/saddle/middleware/ruby_timeout.rb
saddle-0.0.32 lib/saddle/middleware/ruby_timeout.rb
saddle-0.0.31 lib/saddle/middleware/ruby_timeout.rb
saddle-0.0.30 lib/saddle/middleware/ruby_timeout.rb