【发布时间】:2019-12-24 22:04:00
【问题描述】:
我想在 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 来调出可以实现的方法,我将不胜感激。
【问题讨论】:
标签: java android kotlin android-volley