错误与兼容回调
Suspend API
核心 suspend API 失败时抛出 BimError:
kotlin
try {
BimImManager.getInstance().chatService.sendMessage(message, conversation)
} catch (error: BimError) {
println("code=${error.code}, message=${error.message}")
}常用稳定错误码定义在 BimErrorCode 中,包括 NETWORK_ERROR、INTERNAL_ERROR、IM_SEND_ERROR、NOT_LOGGED_IN、TIMEOUT、SDK_RELEASED、SESSION_CHANGED、OPERATION_CANCELLED、LOCAL_STORAGE_ERROR 和 MEDIA_EXPIRED。服务端业务错误码会按 SDK 约定保留。
Callback API
历史 suspend + BimResultCallback / BimSendCallback 重载仍可用于兼容:
kotlin
interface BimResultCallback<T> {
fun onSuccess(data: T)
fun onError(code: Int, msg: String)
}
interface BimSendCallback {
fun onSuccess()
fun onError(code: Int, msg: String)
}各 Service 的兼容 callback 重载仍是 Kotlin suspend 方法,实际使用时应实现对应接口。callback 成功或失败只回调一次;协程取消不会被转换成成功。
