@@ -7,6 +7,7 @@ import com.adamratzman.spotify.http.HttpRequestMethod
77import com.adamratzman.spotify.models.Token
88import com.adamratzman.spotify.models.serialization.nonstrictJson
99import com.adamratzman.spotify.models.serialization.toObject
10+ import io.ktor.client.features.ServerResponseException
1011import kotlinx.coroutines.CancellationException
1112import kotlinx.serialization.json.Json
1213
@@ -639,7 +640,10 @@ public class SpotifyClientApiBuilder(
639640 } catch (e: CancellationException ) {
640641 throw e
641642 } 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 (
643647 " Invalid credentials provided in the login process (clientId=$clientId , clientSecret=$clientSecret , authCode=${authorization.authorizationCode} )" ,
644648 e
645649 )
@@ -675,7 +679,9 @@ public class SpotifyClientApiBuilder(
675679 } catch (e: CancellationException ) {
676680 throw e
677681 } 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 (
679685 " Invalid credentials provided in the login process (clientId=$clientId , clientSecret=$clientSecret , authCode=${authorization.authorizationCode} )" ,
680686 e
681687 )
@@ -783,7 +789,9 @@ public class SpotifyAppApiBuilder(
783789 } catch (e: CancellationException ) {
784790 throw e
785791 } 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 (
787795 " Invalid credentials provided in the login process (clientId=$clientId , clientSecret=$clientSecret )" ,
788796 e
789797 )
0 commit comments