@@ -56,7 +56,7 @@ object NetworkModule {
5656 val requestAuthenticationPlugin = createClientPlugin(" requestAuthenticatorPlugin" ) {
5757 onRequest { request, _ ->
5858 request.headers {
59- val epoch = (System .currentTimeMillis() / 1000 ). let { if ( BuildConfig . DEBUG ) it - 150 else it }
59+ val epoch = (System .currentTimeMillis() / 1000 )
6060 append(" User-Agent" , " Podcaster/1.0" )
6161 append(" X-Auth-Date" , epoch.toString())
6262 append(" X-Auth-Key" , BuildConfig .API_KEY )
@@ -72,10 +72,19 @@ object NetworkModule {
7272 }
7373 }
7474 install(HttpRequestRetry ) {
75+ modifyRequest { request ->
76+ // The server expects the auth date to be within a 3 minutes time window around the server time
77+ // but sometimes the request time/auth date is off by a few seconds/milliseconds, therefore,
78+ // to solve this, retry the request with a 1.5 minutes offset.
79+ val epoch = (System .currentTimeMillis() / 1000 ) - 150
80+ request.headers[" X-Auth-Date" ] = epoch.toString()
81+ request.headers[" Authorization" ] = authHeader(epoch)
82+ }
7583 retryIf(3 ) { _, httpResponse ->
7684 when {
7785 httpResponse.status.value in 500 .. 599 -> true
7886 httpResponse.status == HttpStatusCode .TooManyRequests -> true
87+ httpResponse.status == HttpStatusCode .Unauthorized -> true
7988 else -> false
8089 }
8190 }
0 commit comments