Kotlin 如何捕获带有协同路由后台调用的Reformation-2中的套接字异常?

Kotlin 如何捕获带有协同路由后台调用的Reformation-2中的套接字异常?,kotlin,Kotlin,当api调用中断时,我将看到套接字错误对话框。我在后台通话中使用了带有改进-2的协同程序。如何正确捕捉这些错误。我的项目使用自动更新,所以它会在一定的时间间隔内更新页面,所以自动更新页面总是有机会来回移动,这会中断服务器请求 ViewModel类: 乐趣更新服务(所有者:LifecycleOwner onSuccess: () -> Unit, onFailure: (reason: PrinterOnEr

当api调用中断时,我将看到套接字错误对话框。我在后台通话中使用了带有改进-2的协同程序。如何正确捕捉这些错误。我的项目使用自动更新,所以它会在一定的时间间隔内更新页面,所以自动更新页面总是有机会来回移动,这会中断服务器请求

ViewModel类:

乐趣更新服务(所有者:LifecycleOwner

                    onSuccess: () -> Unit, 

                    onFailure: (reason: PrinterOnError) -> Unit){

    parentPrinterId?.let { parentPrinterId ->

        realmHelper.getPrinterById(parentPrinterId)?.let { printerData ->

            printerData.service?.let { serviceData ->

                if (serviceData.hasJobsApi()) {

                    serviceData.user?.let { user ->

                        val helper = JobsApiHelper()

                        helper.updateUsersJobList(serviceData.id, owner, onSuccess, onFailure)

                    } ?: run {

                        showDLog("User Not Found")

                        onFailure(UserError(invalidCredentials = false, noUserAttached = true, 
serviceId=serviceData.id)

serviceId=service.id)

片段类:

私人娱乐更新SERSJOBS(){

                    }

                } else {

                    showDLog("Service Does Not have JobsAPI")

                    onFailure(PrinterOnError())
                }
            }

        }
    } ?: run {

        //check if service is attached with valid user

        if (PrinterOnDefaults.defaultService >= 0) {

            realmHelper.getObjectById(ServiceData::class.java, PrinterOnDefaults.defaultService)?.let { service ->

                if (service.hasJobsApi()) {

                    service.user?.let { user ->

                        val helper = JobsApiHelper()

                        helper.updateUsersJobList(service.id, owner, onSuccess, onFailure)

                    } ?: run {

                        showDLog("User Not Found")

                        onFailure(UserError(invalidCredentials = false, noUserAttached = true, 
                    }

                } else {

                    showDLog("Service Does Not have JobsAPI")

                    onFailure(PrinterOnError())

                }

            } ?: run {

                showDLog("Service Not Found")

                onFailure(ServiceError(invalidAuthMethod = false, serviceNotFound = true))

            }

        } else {

            showDLog("Hosted does not support history")

            onFailure(PrinterOnError())

        }
    }
}
    //check if service is attached with valid user

    swipeContainer?.isRefreshing = true

    isRefreshing.postValue(true)

    run {

        requireActivity().window.setFlags(

                WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE,

                WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE)


    }

    model?.updateUsersJobs(this, {

        activity?.runOnUiThread {

            swipeContainer?.isRefreshing = false

            isRefreshing.postValue(false)

            requireActivity().window.clearFlags(

                    WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE)

        }

    }, { error ->

        activity?.runOnUiThread {

            swipeContainer?.isRefreshing = false

            isRefreshing.postValue(false)

            requireActivity().window.clearFlags(

                    WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE)

            if (error is UserError) {

                if (!error.noUserAttached) {

                    DialogHelper().processFailure(this, model?.getActiveUser(), error) {}

                }

            } else {

                DialogHelper().processFailure(this, model?.getActiveUser(), error) {}

            }
        }
    })
}