Skip to content

Commit e04ba85

Browse files
committed
add simple playlist to playlist conversion test
Signed-off-by: Adam Ratzman <[email protected]>
1 parent a13dee2 commit e04ba85

File tree

3 files changed

+20
-4
lines changed

3 files changed

+20
-4
lines changed

src/commonMain/kotlin/com.adamratzman.spotify/Builder.kt

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import com.adamratzman.spotify.http.HttpRequestMethod
77
import com.adamratzman.spotify.models.Token
88
import com.adamratzman.spotify.models.serialization.nonstrictJson
99
import com.adamratzman.spotify.models.serialization.toObject
10+
import io.ktor.client.features.ServerResponseException
1011
import kotlinx.coroutines.CancellationException
1112
import 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
)

src/commonMain/kotlin/com.adamratzman.spotify/models/serialization/SerializationUtils.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,6 @@ internal inline fun <reified T : Any> String.toNullablePagingObject(
202202
internal fun Map<String, JsonElement>.mapToJsonString() = JsonObject(this).toString()
203203

204204
internal fun List<NeedsApi?>.instantiateAllNeedsApiObjects(api: GenericSpotifyApi) {
205-
println("run on ${this.size} items")
206205
this.instantiateLateinitsIfPagingObjects(api)
207206
asSequence().filterNotNull().map { member -> member.getMembersThatNeedApiInstantiation() }.flatten()
208207
.distinct()

src/commonTest/kotlin/com.adamratzman/spotify/pub/PublicPlaylistsApiTest.kt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,4 +85,13 @@ class PublicPlaylistsApiTest {
8585
assertFailsWithSuspend<SpotifyException.BadRequestException> { api.playlists.getPlaylistCovers("adskjfjkasdf") }
8686
}
8787
}
88+
89+
@Test
90+
fun testConvertSimplePlaylistToPlaylist() {
91+
runBlockingTest {
92+
if (!testPrereq()) return@runBlockingTest
93+
val simplePlaylist = api.playlists.getUserPlaylists("adamratzman1").first()!!
94+
assertEquals(simplePlaylist.id, simplePlaylist.toFullPlaylist()?.id)
95+
}
96+
}
8897
}

0 commit comments

Comments
 (0)