@@ -14,6 +14,7 @@ import io.ktor.client.request.*
1414import io.ktor.client.statement.*
1515import io.ktor.utils.io.*
1616import kotlinx.coroutines.*
17+ import kotlinx.serialization.ExperimentalSerializationApi
1718import kotlinx.serialization.decodeFromString
1819import kotlinx.serialization.json.Json
1920import me.stageguard.sctimetable.service.TimeProviderService
@@ -36,6 +37,7 @@ data class LoginInfoData(
3637 val password : String
3738)
3839
40+ @ExperimentalSerializationApi
3941object SuperCourseApiService {
4042
4143 private const val BASE_URL : String = " http://120.55.151.61"
@@ -106,9 +108,13 @@ object SuperCourseApiService {
106108 }))
107109 val result = (response.content.readUTF8Line() ? : " {\" data\" :{\" errorStr\" :\" Empty response content.\" },\" status\" :1}" )
108110 if (Pattern .compile(" errorStr" ).matcher(result).find()) {
109- Either (json.decodeFromString(result) as ErrorLoginReceiptDTO )
111+ Either (try {
112+ json.decodeFromString(result)
113+ } catch (ignored: Exception ) {
114+ ErrorLoginReceiptDTO (__InternalErrorLoginMsg (result), 1 )
115+ } )
110116 } else {
111- Either .invoke<ErrorLoginReceiptDTO , LoginReceiptDTO >(json.decodeFromString(result) as LoginReceiptDTO )
117+ Either .invoke<ErrorLoginReceiptDTO , LoginReceiptDTO >(json.decodeFromString< LoginReceiptDTO > (result))
112118 }
113119
114120 }
@@ -143,13 +149,17 @@ object SuperCourseApiService {
143149 }.execute {
144150 val result = it.content.readUTF8Line() ? : " {\" message\" :\" Empty response content.\" ,\" title\" :\"\" }"
145151 try {
146- Either .invoke<ErrorCourseReceiptDTO , CourseReceiptDTO >(json.decodeFromString(result) as CourseReceiptDTO )
152+ Either .invoke<ErrorCourseReceiptDTO , CourseReceiptDTO >(json.decodeFromString< CourseReceiptDTO > (result))
147153 } catch (error: Exception ) {
148- Either .invoke(json.decodeFromString(result) as ErrorCourseReceiptDTO )
154+ try {
155+ Either .invoke(json.decodeFromString(result))
156+ } catch (ex: Exception ) {
157+ Either .invoke(ErrorCourseReceiptDTO (" decode error" , result))
158+ }
149159 }
150160 }
151161 } catch (ex: Exception ) {
152- Either (ErrorCourseReceiptDTO (" " , ex.toString()))
162+ Either (ErrorCourseReceiptDTO (" internal error " , ex.toString()))
153163 }
154164
155165 fun closeHttpClient () {
0 commit comments