Skip to content

Commit 2fd358e

Browse files
committed
feat: add handle for response
1 parent c472173 commit 2fd358e

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

src/main/kotlin/cc/unitmesh/devti/connector/custom/CustomConnector.kt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ package cc.unitmesh.devti.connector.custom
22

33
import cc.unitmesh.devti.connector.CodeCopilot
44
import cc.unitmesh.devti.settings.DevtiSettingsState
5+
import com.intellij.openapi.diagnostic.Logger
6+
import com.intellij.openapi.diagnostic.logger
57
import kotlinx.serialization.decodeFromString
68
import kotlinx.serialization.json.Json
79
import okhttp3.OkHttpClient
@@ -35,6 +37,8 @@ class CustomConnector : CodeCopilot {
3537
}
3638
}
3739

40+
private val logger = Logger.getInstance(CustomConnector::class.java)
41+
3842
fun prompt(instruction: String, input: String): String {
3943
val body = okhttp3.RequestBody.create(
4044
okhttp3.MediaType.parse("application/json; charset=utf-8"),
@@ -58,6 +62,11 @@ class CustomConnector : CodeCopilot {
5862

5963
val response = client.newCall(request).execute()
6064

65+
if (!response.isSuccessful) {
66+
logger.error("$response")
67+
return ""
68+
}
69+
6170
return response.body()?.string() ?: ""
6271
}
6372

0 commit comments

Comments
 (0)