+
+ ##
+ # Returns on proc for special processing of retries for authorization errors
+ # Only 401s should be retried and only if the credentials are refreshable
+ #
+ # @param [#fetch_access_token!] authorization
+ # OAuth 2 credentials
+ # @return [Proc]
+ def authorization_error_handler(authorization)
+ can_refresh = authorization.respond_to?(:refresh_token) && auto_refresh_token
+ Proc.new do |exception, tries|
+ next unless exception.kind_of?(AuthorizationError)
+ if can_refresh
+ begin
+ logger.debug("Attempting refresh of access token & retry of request")
+ authorization.fetch_access_token!
+ next
+ rescue Signet::AuthorizationError
+ end
+ end
+ raise exception
+ end
+ end
+
+ ##
+ # Returns on proc for special processing of retries as not all client errors
+ # are recoverable. Only 401s should be retried (via authorization_error_handler)
+ #
+ # @return [Proc]
+ def client_error_handler
+ Proc.new do |exception, tries|
+ raise exception if exception.kind_of?(ClientError)
+ end
+ end
+