From d8aba7a99ae9377b0c0c1b747a956e9f6ad0b98f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohnic=CC=81?= Date: Tue, 19 Jun 2012 11:11:22 +0200 Subject: [PATCH] raise proper exception for Excon timeout --- Gemfile | 2 +- lib/faraday/adapter/excon.rb | 10 +++++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/Gemfile b/Gemfile index e82dd614..2565b04c 100644 --- a/Gemfile +++ b/Gemfile @@ -7,7 +7,7 @@ end group :test do gem 'em-http-request', '~> 1.0', :require => 'em-http' gem 'em-synchrony', '~> 1.0', :require => ['em-synchrony', 'em-synchrony/em-http'], :platforms => :ruby_19 - gem 'excon', '~> 0.9', '> 0.9.6' + gem 'excon', '~> 0.14' gem 'httpclient', '~> 2.2' gem 'net-http-persistent', '~> 2.5', :require => false gem 'leftright', '~> 0.9', :require => false diff --git a/lib/faraday/adapter/excon.rb b/lib/faraday/adapter/excon.rb index 2a1724fd..caafe15e 100644 --- a/lib/faraday/adapter/excon.rb +++ b/lib/faraday/adapter/excon.rb @@ -40,10 +40,14 @@ module Faraday save_response(env, resp.status.to_i, resp.body, resp.headers) @app.call env - rescue ::Excon::Errors::SocketError - raise Error::ConnectionFailed, $! + rescue ::Excon::Errors::SocketError => err + if err.message =~ /\btimeout\b/ + raise Error::TimeoutError, err + else + raise Error::ConnectionFailed, err + end rescue ::Excon::Errors::Timeout => err - raise Faraday::Error::TimeoutError, err + raise Error::TimeoutError, err end # TODO: support streaming requests