lib/ably/rest/client.rb in ably-1.1.2 vs lib/ably/rest/client.rb in ably-1.1.3
- old
+ new
@@ -30,10 +30,17 @@
max_retry_count: 3
}.freeze
FALLBACK_RETRY_TIMEOUT = 10 * 60
+ # Faraday 1.0 introduced new error types, however we want to support Faraday <1 too which only used Faraday::ClientError
+ FARADAY_CLIENT_OR_SERVER_ERRORS = if defined?(Faraday::ParsingError)
+ [Faraday::ClientError, Faraday::ServerError, Faraday::ConnectionFailed, Faraday::SSLError, Faraday::ParsingError]
+ else
+ Faraday::ClientError
+ end
+
def_delegators :auth, :client_id, :auth_options
# Custom environment to use such as 'sandbox' when testing the client library against an alternate Ably environment
# @return [String]
attr_reader :environment
@@ -557,10 +564,13 @@
if add_request_ids
request.params[:request_id] = request_id
request.options.context = {} if request.options.context.nil?
request.options.context[:request_id] = request_id
end
+ if options[:qs_params]
+ request.params.merge!(options[:qs_params])
+ end
unless options[:send_auth_header] == false
request.headers[:authorization] = auth.auth_header
if options[:headers]
options[:headers].map do |key, val|
request.headers[key] = val
@@ -576,11 +586,11 @@
end
set_preferred_fallback_connection conn
end
end
- rescue Faraday::TimeoutError, Faraday::ClientError, Ably::Exceptions::ServerError => error
+ rescue *([Faraday::TimeoutError, Ably::Exceptions::ServerError] + FARADAY_CLIENT_OR_SERVER_ERRORS) => error
retry_sequence_id ||= SecureRandom.urlsafe_base64(4)
time_passed = Time.now - requested_at
if can_fallback_to_alternate_ably_host? && (retry_count < max_retry_count) && (time_passed <= max_retry_duration)
retry_count += 1
@@ -596,10 +606,10 @@
end
case error
when Faraday::TimeoutError
raise Ably::Exceptions::ConnectionTimeout.new(error.message, nil, Ably::Exceptions::Codes::CONNECTION_TIMED_OUT, error, { request_id: request_id })
- when Faraday::ClientError
+ when *FARADAY_CLIENT_OR_SERVER_ERRORS
# request_id is also available in the request context
raise Ably::Exceptions::ConnectionError.new(error.message, nil, Ably::Exceptions::Codes::CONNECTION_FAILED, error, { request_id: request_id })
else
raise error
end