Skip to content

Commit 19b2dae

Browse files
committed
replace Exception with Throwable in SseClientTransport error handling and try/catch cancel in closeResources
1 parent 7fb7916 commit 19b2dae

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

src/commonMain/kotlin/io/modelcontextprotocol/kotlin/sdk/client/SSEClientTransport.kt

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ public class SseClientTransport(
111111
val text = response.bodyAsText()
112112
error("Error POSTing to endpoint (HTTP ${response.status}): $text")
113113
}
114-
} catch (e: Exception) {
114+
} catch (e: Throwable) {
115115
_onError(e)
116116
throw e
117117
}
@@ -144,7 +144,7 @@ public class SseClientTransport(
144144
}
145145
} catch (e: CancellationException) {
146146
throw e
147-
} catch (e: Exception) {
147+
} catch (e: Throwable) {
148148
_onError(e)
149149
throw e
150150
} finally {
@@ -157,7 +157,7 @@ public class SseClientTransport(
157157
val path = if (eventData.startsWith("/")) eventData.substring(1) else eventData
158158
val endpointUrl = Url("$baseUrl/$path")
159159
endpoint.complete(endpointUrl.toString())
160-
} catch (e: Exception) {
160+
} catch (e: Throwable) {
161161
_onError(e)
162162
endpoint.completeExceptionally(e)
163163
throw e
@@ -177,9 +177,13 @@ public class SseClientTransport(
177177
if (!initialized.compareAndSet(expectedValue = true, newValue = false)) return
178178

179179
job?.cancelAndJoin()
180-
if (::session.isInitialized) session.cancel()
181-
if (::scope.isInitialized) scope.cancel()
182-
endpoint.cancel()
180+
try {
181+
if (::session.isInitialized) session.cancel()
182+
if (::scope.isInitialized) scope.cancel()
183+
endpoint.cancel()
184+
} catch (e: Throwable) {
185+
_onError(e)
186+
}
183187

184188
_onClose()
185189
}

0 commit comments

Comments
 (0)