@@ -85,23 +85,23 @@ public class HttpConnection constructor(
85
85
86
86
public suspend fun execute (
87
87
additionalHeaders : List <HttpHeader >? = null,
88
- retryIf502 : Boolean = true
88
+ retryIfInternalServerError : Boolean = true
89
89
): HttpResponse {
90
90
val httpRequest = buildRequest(additionalHeaders)
91
91
92
92
try {
93
93
return HttpClient ().request< io.ktor.client.statement.HttpResponse > (httpRequest).let { response ->
94
94
val respCode = response.status.value
95
95
96
- if (respCode == 502 && retryIf502 ) {
96
+ if (respCode in 500 .. 599 && retryIfInternalServerError ) {
97
97
api?.logger?.logError(
98
98
false ,
99
- " Received 502 (Invalid response ) for URL $url and $this (${response.readText()} )\n Retrying.." ,
99
+ " Received $respCode (Internal Server Error ) for URL $url and $this (${response.readText()} )\n Retrying.." ,
100
100
null
101
101
)
102
- return @let execute(additionalHeaders, retryIf502 = false )
103
- } else if (respCode == 502 && ! retryIf502 ) {
104
- api?.logger?.logWarning(" Recieved 502 (Invalid response ) for URL $url and $this \n Not retrying" )
102
+ return @let execute(additionalHeaders, retryIfInternalServerError = false )
103
+ } else if (respCode in 500 .. 599 && ! retryIfInternalServerError ) {
104
+ api?.logger?.logWarning(" Received $respCode (Internal Server Error ) for URL $url and $this \n Not retrying" )
105
105
}
106
106
107
107
if (respCode == 429 ) {
@@ -114,7 +114,7 @@ public class HttpConnection constructor(
114
114
)
115
115
116
116
delay(ratelimit * 1000 )
117
- return @let execute(additionalHeaders, retryIf502 = retryIf502 )
117
+ return @let execute(additionalHeaders, retryIfInternalServerError = retryIfInternalServerError )
118
118
} else throw SpotifyRatelimitedException (ratelimit)
119
119
}
120
120
@@ -125,7 +125,7 @@ public class HttpConnection constructor(
125
125
api.refreshToken()
126
126
val newAdditionalHeaders = additionalHeaders?.toMutableList() ? : mutableListOf ()
127
127
newAdditionalHeaders.add(0 , HttpHeader (" Authorization" , " Bearer ${api.token.accessToken} " ))
128
- return execute(newAdditionalHeaders, retryIf502 )
128
+ return execute(newAdditionalHeaders, retryIfInternalServerError )
129
129
}
130
130
131
131
return HttpResponse (
0 commit comments