def handle_exception(exception, type, request_uuid, expires_at, attempts)
      result = request_uuid
      if exception.respond_to?(:http_code)
        case exception.http_code
        when 301, 302 # MovedPermanently, Found
          handle_redirect(exception, type, request_uuid)
        when 401 # Unauthorized
          raise Exceptions::Unauthorized.new(exception.http_body, exception)
        when 403 # Forbidden
          @auth_client.expired
          raise Exceptions::RetryableError.new("Authorization expired", exception)
        when 449 # RetryWith
          result = handle_retry_with(exception, type, request_uuid, expires_at, attempts)
        when 500 # InternalServerError
          raise Exceptions::InternalServerError.new(exception.http_body, @options[:server_name])
        else
          @stats["request failures"].update("#{type} - #{exception.http_code}")
          result = nil
        end
      elsif exception.is_a?(BalancedHttpClient::NotResponding)
        handle_not_responding(exception, type, request_uuid, expires_at, attempts)
      else
        @stats["request failures"].update("#{type} - #{exception.class.name}")
        result = nil
      end
      result
    end
def handle_exception(exception, type, request_uuid, expires_at, attempts)
      result = request_uuid
      if exception.respond_to?(:http_code)
        case exception.http_code
        when 301, 302 # MovedPermanently, Found
          handle_redirect(exception, type, request_uuid)
        when 401 # Unauthorized
          raise Exceptions::Unauthorized.new(exception.http_body, exception)
        when 403 # Forbidden
          @auth_client.expired
          raise Exceptions::RetryableError.new("Authorization expired", exception)
        when 449 # RetryWith
          result = handle_retry_with(exception, type, request_uuid, expires_at, attempts)
        when 500 # InternalServerError
          raise Exceptions::InternalServerError.new(exception.http_body, @options[:server_name])
        else
          @stats["request failures"].update("#{type} - #{exception.http_code}")
          result = nil
        end
      elsif exception.is_a?(BalancedHttpClient::NotResponding)
        handle_not_responding(exception, type, request_uuid, expires_at, attempts)
      else
        @stats["request failures"].update("#{type} - #{exception.class.name}")
        result = nil
      end
      result
    end
Examine exception to determine whether to setup retry, raise new exception, or re-raise

 @param [StandardError] exception raised
 @param [String] action from request type
 @param [String] type of request for use in logging
 @param [String] request_uuid originally created for this request
 @param [Time] expires_at time for request
 @param [Integer] attempts to make request

 @return [String, NilClass] request UUID to be used on retry or nil if to raise instead

 @raise [Exceptions::Unauthorized] authorization failed
 @raise [Exceptions::ConnectivityFailure] cannot connect to server, lost connection
   to it, or it is out of service or too busy to respond
 @raise [Exceptions::RetryableError] request failed but if retried may succeed
 @raise [Exceptions::InternalServerError] internal error in server being accessed