@@ -7,6 +7,7 @@ import com.adamratzman.spotify.http.HttpRequestMethod
7
7
import com.adamratzman.spotify.models.Token
8
8
import com.adamratzman.spotify.models.serialization.nonstrictJson
9
9
import com.adamratzman.spotify.models.serialization.toObject
10
+ import io.ktor.client.features.ServerResponseException
10
11
import kotlinx.coroutines.CancellationException
11
12
import kotlinx.serialization.json.Json
12
13
@@ -639,7 +640,10 @@ public class SpotifyClientApiBuilder(
639
640
} catch (e: CancellationException ) {
640
641
throw e
641
642
} catch (e: Exception ) {
642
- throw SpotifyException .AuthenticationException (
643
+ // BadRequestException -> ServerResponseException
644
+ if ((e.cause as ? ServerResponseException )?.response?.status?.value in 500 .. 599 ) {
645
+ throw SpotifyException .BadRequestException (" Spotify internal server error" , e)
646
+ } else throw SpotifyException .AuthenticationException (
643
647
" Invalid credentials provided in the login process (clientId=$clientId , clientSecret=$clientSecret , authCode=${authorization.authorizationCode} )" ,
644
648
e
645
649
)
@@ -675,7 +679,9 @@ public class SpotifyClientApiBuilder(
675
679
} catch (e: CancellationException ) {
676
680
throw e
677
681
} catch (e: Exception ) {
678
- throw SpotifyException .AuthenticationException (
682
+ if ((e.cause as ? ServerResponseException )?.response?.status?.value in 500 .. 599 ) {
683
+ throw SpotifyException .BadRequestException (" Spotify internal server error" , e)
684
+ } else throw SpotifyException .AuthenticationException (
679
685
" Invalid credentials provided in the login process (clientId=$clientId , clientSecret=$clientSecret , authCode=${authorization.authorizationCode} )" ,
680
686
e
681
687
)
@@ -783,7 +789,9 @@ public class SpotifyAppApiBuilder(
783
789
} catch (e: CancellationException ) {
784
790
throw e
785
791
} catch (e: Exception ) {
786
- throw SpotifyException .AuthenticationException (
792
+ if ((e.cause as ? ServerResponseException )?.response?.status?.value in 500 .. 599 ) {
793
+ throw SpotifyException .BadRequestException (" Spotify internal server error" , e)
794
+ } else throw SpotifyException .AuthenticationException (
787
795
" Invalid credentials provided in the login process (clientId=$clientId , clientSecret=$clientSecret )" ,
788
796
e
789
797
)
0 commit comments