File tree Expand file tree Collapse file tree
composeApp/src/commonMain/kotlin/com/jankinwu/fntv/client/data/network/impl Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -32,6 +32,7 @@ import io.ktor.client.statement.HttpResponse
3232import io.ktor.client.statement.bodyAsChannel
3333import io.ktor.client.statement.bodyAsText
3434import io.ktor.http.HttpHeaders
35+ import io.ktor.http.isSuccess
3536import io.ktor.serialization.jackson.jackson
3637import io.ktor.utils.io.readUTF8Line
3738
@@ -122,6 +123,17 @@ class FlyNarwhalApiImpl : FlyNarwhalApi {
122123 }
123124
124125 private suspend fun readDanmakuFromSse (response : HttpResponse ): Map <String , List <Danmaku >> {
126+ if (! response.status.isSuccess()) {
127+ val errorBody = response.bodyAsText()
128+ val errorMessage = try {
129+ mapper.readValue<SmartAnalysisResult <* >>(errorBody).msg
130+ } catch (_: Exception ) {
131+ errorBody
132+ }
133+ logger.e { " SSE request failed with status ${response.status} : $errorMessage " }
134+ throw IllegalStateException (errorMessage.ifBlank { " SSE request failed with status ${response.status} " })
135+ }
136+
125137 val channel = response.bodyAsChannel()
126138 var eventName: String? = null
127139 val dataLines = mutableListOf<String >()
You can’t perform that action at this time.
0 commit comments