java如何解析Kotlin中截取的来自服务器的错误
我想获得从Kotlin中的服务器返回的确切错误消息。我目前的处理方式如下
Response.ErrorListener {error ->
// regProgress.hide()
val resp = error
if(error is ClientError ){
Toast.makeText(context!!.applicationContext, "User already exists", Toast.LENGTH_SHORT).show()
}
else if(error is NetworkError){
Toast.makeText(context!!.applicationContext, "Network error \nPlease check your network connection", Toast.LENGTH_SHORT).show()
}
else if(error is TimeoutError){
Toast.makeText(context!!.applicationContext, "Request time out", Toast.LENGTH_SHORT).show()
}
else if(error is AuthFailureError){
Toast.makeText(context!!.applicationContext, "Bad request \nKindly check details provided", Toast.LENGTH_SHORT).show()
}
else if(error is ServerError){
Toast.makeText(context!!.applicationContext, "Internal server error \nPlease try again", Toast.LENGTH_SHORT).show()
}
else if(error is NoConnectionError){
Toast.makeText(context!!.applicationContext, "Poor connection \n" +
"Please check your network connection", Toast.LENGTH_SHORT).show()
}
regProgressBar.visibility = View.GONE
registerBtn.visibility = View.VISIBLE
// val responseBody = error.networkResponse.data.toString()
Log.e("Data", "Response $resp")
// Log.e("Network", "Response ${error.networkResponse}")
// Toast.makeText(context!!.applicationContext, "$it", Toast.LENGTH_SHORT).show()
}
我尝试了parseNetwork方法,但出现错误。如果有一种自动获取方法的方法,比如使用ctrl o
来提出可以实现的方法,我将非常感激
# 1 楼答案
我能用计算机解决这个问题