Skip to content

Commit 4b05542

Browse files
committed
Added timeout for retry.
1 parent ea317dc commit 4b05542

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

‎SpotifyAPI/Web/SpotifyWebAPI.cs‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public void Dispose()
5353
/// <summary>
5454
/// Should a failed request (Error 500, 502, or 503) be automatically retried or not.
5555
/// </summary>
56-
public bool UseAutoRetry { get; set; } = false;
56+
public bool UseAutoRetry { get; set; } = true;
5757

5858
/// <summary>
5959
/// Maximum number of tries for one failed request.
@@ -1834,6 +1834,7 @@ private ListResponse<bool> DownloadDataAltAndExtract(string url)
18341834
ListResponse<bool> data = null;
18351835
do
18361836
{
1837+
if (data != null) { System.Threading.Thread.Sleep(RetryAfter); }
18371838
Tuple<ResponseInfo, JToken> res = DownloadDataAlt<JToken>(url);
18381839
data = ExtractDataFromAltDownload(res);
18391840

@@ -1854,6 +1855,7 @@ private async Task<ListResponse<bool>> DownloadDataAltAndExtractAsync(string url
18541855
ListResponse<bool> data = null;
18551856
do
18561857
{
1858+
if (data != null) { await Task.Delay(RetryAfter); }
18571859
Tuple<ResponseInfo, JToken> res = await DownloadDataAltAsync<JToken>(url);
18581860
data = ExtractDataFromAltDownload(res);
18591861

@@ -1898,6 +1900,7 @@ public T UploadData<T>(string url, string uploadData, string method = "POST") wh
18981900
WebClient.SetHeader("Authorization", TokenType + " " + AccessToken);
18991901
WebClient.SetHeader("Content-Type", "application/json");
19001902

1903+
if (response != null) { System.Threading.Thread.Sleep(RetryAfter); }
19011904
response = WebClient.UploadJson<T>(url, uploadData, method);
19021905

19031906
response.Item2.AddResponseInfo(response.Item1);
@@ -1924,6 +1927,7 @@ public async Task<T> UploadDataAsync<T>(string url, string uploadData, string me
19241927
WebClient.SetHeader("Authorization", TokenType + " " + AccessToken);
19251928
WebClient.SetHeader("Content-Type", "application/json");
19261929

1930+
if (response != null) { await Task.Delay(RetryAfter); }
19271931
response = await WebClient.UploadJsonAsync<T>(url, uploadData, method);
19281932

19291933
response.Item2.AddResponseInfo(response.Item1);
@@ -1944,6 +1948,7 @@ public T DownloadData<T>(string url) where T : BasicModel
19441948
Tuple<ResponseInfo, T> response = null;
19451949
do
19461950
{
1951+
if(response != null) { System.Threading.Thread.Sleep(RetryAfter); }
19471952
response = DownloadDataAlt<T>(url);
19481953

19491954
response.Item2.AddResponseInfo(response.Item1);
@@ -1965,6 +1970,7 @@ public async Task<T> DownloadDataAsync<T>(string url) where T : BasicModel
19651970
Tuple<ResponseInfo, T> response = null;
19661971
do
19671972
{
1973+
if (response != null) { await Task.Delay(RetryAfter); }
19681974
response = await DownloadDataAltAsync<T>(url);
19691975

19701976
response.Item2.AddResponseInfo(response.Item1);

0 commit comments

Comments
 (0)