# Class BackOffHandler (1.73.0)

<button class="button button-with-icon cloud-select-dropdown__button " aria-haspopup="true">Version latest</button>

- [1.73.0 (latest)](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Http.BackOffHandler)
- [1.69.0](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/1.69.0/Google.Apis.Http.BackOffHandler)
- [1.68.0](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/1.68.0/Google.Apis.Http.BackOffHandler)
- [1.60.0](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/1.60.0/Google.Apis.Http.BackOffHandler)
- [1.59.0](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/1.59.0/Google.Apis.Http.BackOffHandler)
- [1.55.0](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/1.55.0/Google.Apis.Http.BackOffHandler)
- [1.50.0](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/1.50.0/Google.Apis.Http.BackOffHandler)

    public class BackOffHandler : IHttpUnsuccessfulResponseHandler, IHttpExceptionHandler

A thread-safe back-off handler which handles an abnormal HTTP response or an exception with
[IBackOff](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Util.IBackOff).

## Inheritance

[object](https://learn.microsoft.com/dotnet/api/system.object) \> BackOffHandler

## Implements

[IHttpUnsuccessfulResponseHandler](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Http.IHttpUnsuccessfulResponseHandler), [IHttpExceptionHandler](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Http.IHttpExceptionHandler)

## Inherited Members

[object.Equals(object)](https://learn.microsoft.com/dotnet/api/system.object.equals#system-object-equals(system-object)) [object.Equals(object, object)](https://learn.microsoft.com/dotnet/api/system.object.equals#system-object-equals(system-object-system-object)) [object.GetHashCode()](https://learn.microsoft.com/dotnet/api/system.object.gethashcode) [object.GetType()](https://learn.microsoft.com/dotnet/api/system.object.gettype) [object.MemberwiseClone()](https://learn.microsoft.com/dotnet/api/system.object.memberwiseclone) [object.ReferenceEquals(object, object)](https://learn.microsoft.com/dotnet/api/system.object.referenceequals) [object.ToString()](https://learn.microsoft.com/dotnet/api/system.object.tostring)

## Namespace

[Google.Apis.Http](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Http)

## Assembly

Google.Apis.Core.dll

## Constructors

### BackOffHandler(Initializer)

    public BackOffHandler(BackOffHandler.Initializer initializer)

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

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `initializer` | `https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Http.BackOffHandlerhttps://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Http.BackOffHandler.Initializer` |

### BackOffHandler(IBackOff)

    public BackOffHandler(IBackOff backOff)

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

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `backOff` | `https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Util.IBackOff` The back-off policy. |

## Properties

### BackOff

    public IBackOff BackOff { get; }

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

| **Property Value** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Util.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](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Http.BackOffHandler.Initializer#Google_Apis_Http_BackOffHandler_Initializer_DefaultHandleExceptionFunc).

| **Property Value** ||
|---|---|
| **Type** | **Description** |
| `https://learn.microsoft.com/dotnet/api/system.func-2https://learn.microsoft.com/dotnet/api/system.exceptionhttps://learn.microsoft.com/dotnet/api/system.boolean` |   |

### 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](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Http.BackOffHandler.Initializer#Google_Apis_Http_BackOffHandler_Initializer_DefaultHandleUnsuccessfulResponseFunc).

| **Property Value** ||
|---|---|
| **Type** | **Description** |
| `https://learn.microsoft.com/dotnet/api/system.func-2https://learn.microsoft.com/dotnet/api/system.net.http.httpresponsemessagehttps://learn.microsoft.com/dotnet/api/system.boolean` |   |

### 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** ||
|---|---|
| **Type** | **Description** |
| `https://learn.microsoft.com/dotnet/api/system.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** ||
|---|---|
| **Name** | **Description** |
| `args` | `https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Http.HandleExceptionArgs` Handle exception argument which properties such as the request, exception, current failed try. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://learn.microsoft.com/dotnet/api/system.threading.tasks.task-1https://learn.microsoft.com/dotnet/api/system.boolean` | 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** ||
|---|---|
| **Name** | **Description** |
| `args` | `https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Http.HandleUnsuccessfulResponseArgs` Handle response argument which contains properties such as the request, response, current failed try. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://learn.microsoft.com/dotnet/api/system.threading.tasks.task-1https://learn.microsoft.com/dotnet/api/system.boolean` | 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** ||
|---|---|
| **Name** | **Description** |
| `ts` | `https://learn.microsoft.com/dotnet/api/system.timespan` TimeSpan to wait (and block the current thread). |
| `cancellationToken` | `https://learn.microsoft.com/dotnet/api/system.threading.cancellationtoken` The cancellation token in case the user wants to cancel the operation in the middle. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://learn.microsoft.com/dotnet/api/system.threading.tasks.task` |   |

## Extension Method

[Utilities.ThrowIfNull\<T\>(T, string)](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Util.Utilities#Google_Apis_Util_Utilities_ThrowIfNull__1___0_System_String_)