Class BackOffHandler (1.60.0)

public class BackOffHandler : IHttpUnsuccessfulResponseHandler, IHttpExceptionHandler

A thread-safe back-off handler which handles an abnormal HTTP response or an exception with IBackOff.

Inheritance

object > BackOffHandler

Namespace

GoogleApisHttp

Assembly

Google.Apis.Core.dll

Constructors

BackOffHandler(Initializer)

public BackOffHandler(BackOffHandler.Initializer initializer)

Constructs a new back-off handler with the given initializer.

Parameter
NameDescription
initializerBackOffHandlerInitializer

BackOffHandler(IBackOff)

public BackOffHandler(IBackOff backOff)

Constructs a new back-off handler with the given back-off.

Parameter
NameDescription
backOffIBackOff

The back-off policy.

Properties

BackOff

public IBackOff BackOff { get; }

Gets the back-off policy used by this back-off handler.

Property Value
TypeDescription
IBackOff

HandleExceptionFunc

public Func<Exception, bool> HandleExceptionFunc { get; }

Gets a delegate function which indicates whether this back-off handler should handle an exception. The default is DefaultHandleExceptionFunc.

Property Value
TypeDescription
FuncExceptionbool

HandleUnsuccessfulResponseFunc

public Func<HttpResponseMessage, bool> HandleUnsuccessfulResponseFunc { get; }

Gets a delegate function which indicates whether this back-off handler should handle an abnormal HTTP response. The default is DefaultHandleUnsuccessfulResponseFunc.

Property Value
TypeDescription
FuncHttpResponseMessagebool

MaxTimeSpan

public TimeSpan MaxTimeSpan { get; }

Gets the maximum time span to wait. If the back-off instance returns a greater time span, the handle method returns false. Default value is 16 seconds per a retry request.

Property Value
TypeDescription
TimeSpan

Methods

HandleExceptionAsync(HandleExceptionArgs)

public virtual Task<bool> HandleExceptionAsync(HandleExceptionArgs args)

Handles an exception thrown when sending a HTTP request. A simple rule must be followed, if you modify the request object in a way that the exception can be resolved, you must return true.

Parameter
NameDescription
argsHandleExceptionArgs

Handle exception argument which properties such as the request, exception, current failed try.

Returns
TypeDescription
Taskbool

Whether this handler has made a change that requires the request to be resent.

HandleResponseAsync(HandleUnsuccessfulResponseArgs)

public virtual Task<bool> HandleResponseAsync(HandleUnsuccessfulResponseArgs args)

Handles an abnormal response when sending a HTTP request. A simple rule must be followed, if you modify the request object in a way that the abnormal response can be resolved, you must return true.

Parameter
NameDescription
argsHandleUnsuccessfulResponseArgs

Handle response argument which contains properties such as the request, response, current failed try.

Returns
TypeDescription
Taskbool

Whether this handler has made a change that requires the request to be resent.

Wait(TimeSpan, CancellationToken)

protected virtual Task Wait(TimeSpan ts, CancellationToken cancellationToken)

Waits the given time span. Overriding this method is recommended for mocking purposes.

Parameters
NameDescription
tsTimeSpan

TimeSpan to wait (and block the current thread).

cancellationTokenCancellationToken

The cancellation token in case the user wants to cancel the operation in the middle.

Returns
TypeDescription
Task

Extension Method