Skip to content

Commit 2abb34c

Browse files
committed
Fix catching CancellationException
1 parent 55df3f7 commit 2abb34c

File tree

3 files changed

+13
-0
lines changed

3 files changed

+13
-0
lines changed

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import com.adamratzman.spotify.models.SpotifyAuthenticationException
77
import com.adamratzman.spotify.models.Token
88
import com.adamratzman.spotify.models.serialization.toObject
99
import com.adamratzman.spotify.utils.runBlocking
10+
import kotlinx.coroutines.CancellationException
1011
import kotlinx.coroutines.CoroutineScope
1112
import kotlinx.coroutines.Job
1213
import kotlinx.coroutines.launch
@@ -279,6 +280,8 @@ class SpotifyClientApiBuilder(
279280
options.enableLogger,
280281
options.testTokenValidity
281282
)
283+
} catch (e: CancellationException) {
284+
throw e
282285
} catch (e: Exception) {
283286
throw SpotifyAuthenticationException("Invalid credentials provided in the login process", e)
284287
}
@@ -378,6 +381,8 @@ class SpotifyAppApiBuilder(
378381
options.enableLogger,
379382
options.testTokenValidity
380383
)
384+
} catch (e: CancellationException) {
385+
throw e
381386
} catch (e: Exception) {
382387
throw SpotifyAuthenticationException("Invalid credentials provided in the login process", e)
383388
}

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import kotlin.coroutines.resume
1111
import kotlin.coroutines.resumeWithException
1212
import kotlin.coroutines.suspendCoroutine
1313
import kotlin.jvm.JvmOverloads
14+
import kotlinx.coroutines.CancellationException
1415
import kotlinx.coroutines.CoroutineScope
1516
import kotlinx.coroutines.Dispatchers
1617
import kotlinx.coroutines.ExperimentalCoroutinesApi
@@ -73,6 +74,8 @@ open class SpotifyRestAction<T> internal constructor(protected val api: SpotifyA
7374
hasRunBacking = true
7475
return@withContext try {
7576
supplier().also { hasCompletedBacking = true }
77+
} catch (e: CancellationException) {
78+
throw e
7679
} catch (e: Throwable) {
7780
throw e
7881
}
@@ -91,6 +94,8 @@ open class SpotifyRestAction<T> internal constructor(protected val api: SpotifyA
9194
try {
9295
val result = suspendComplete()
9396
consumer(result)
97+
} catch (e: CancellationException) {
98+
throw e
9499
} catch (t: Throwable) {
95100
failure(t)
96101
}

src/commonMain/kotlin/com.adamratzman.spotify/http/HttpConnection.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import io.ktor.http.ContentType
1616
import io.ktor.http.HttpMethod
1717
import io.ktor.http.content.ByteArrayContent
1818
import io.ktor.http.content.TextContent
19+
import kotlinx.coroutines.CancellationException
1920
import kotlinx.coroutines.delay
2021
import kotlinx.io.core.toByteArray
2122
import kotlinx.io.core.use
@@ -138,6 +139,8 @@ internal class HttpConnection constructor(
138139
}
139140
)
140141
}
142+
} catch (e: CancellationException) {
143+
throw e
141144
} catch (e: ResponseException) {
142145
throw SpotifyException.BadRequestException(e)
143146
}

0 commit comments

Comments
 (0)