mirror of
https://github.com/Sarsoo/Spotify.NET.git
synced 2024-12-27 00:16:26 +00:00
1.6 KiB
1.6 KiB
id | title |
---|---|
retry_handling | Retry Handling |
In Error Handling we already found out that requests can fail. We provide a way to automatically retry requests via retry handlers. Note, by default no retries are performed.
var config = SpotifyClientConfig
.CreateDefault()
.WithRetryHandler(new YourCustomRetryHandler())
IRetryHandler
only needs one function:
public class YourCustomRetryHandler : IRetryHandler
{
public Task<IResponse> HandleRetry(IRequest request, IResponse response, IRetryHandler.RetryFunc retry)
{
// request is the sent request and response the received response, obviously?
// don't retry:
return response;
// retry once
var newResponse = retry(request);
return newResponse;
// use retry as often as you want, make sure to return a response
}
}
SimpleRetryHandler
A SimpleRetryHandler
is included, which contains the following retry logic:
- Retries the (configurable) status codes: 500, 502, 503 and 429
RetryAfter
- specifies the delay between retried callsRetryTimes
- specifies the maxiumum amount of performed retries per callTooManyRequestsConsumesARetry
- Whether a failure of type "Too Many Requests" should use up one of the retry attempts.
var config = SpotifyClientConfig
.CreateDefault()
.WithRetryHandler(new SimpleRetryHandler() { RetryAfter = TimeSpan.FromSeconds(1) });
var spotify = new SpotifyClient(config);