Mono.create { sink ->
client.newCall(httpRequest).enqueue(object : com.squareup.okhttp.Callback {
override fun onFailure(request: Request, e: java.io.IOException) {
sink.error(e)
}
override fun onResponse(response: com.squareup.okhttp.Response) {
try {
if (!response.isSuccessful) {
throw IOException("Error: ${response.code()} ${response.message()}")
} else {
sink.success(mapper.readValue(response.body().string()))
}
} catch (e: Exception) {
sink.error(e)
}
}
})
}
When executing a Test where an error occurs in InvocationHandler, it takes a while for the system to exit after the exception is thrown. It looks like the probable cause is that the background thread that calls the openai api is not cleaned up and runs regardless of the error. This did not happen when I used
OpenAiApiClientdefined in the spring boot starter that uses a spring webclient.suspicious code:
https://github.com/mscheong01/interfAIce/blob/main/core/src/main/kotlin/io/github/mscheong01/interfaice/openai/DefaultOkHttpOpenAiClient.kt