我正在使用一个函数来从API检索数据。 即使状态码不是200,此API也会发送回数据。
var mQueue = Volley.newRequestQueue(this) val url =“ randomurl.com”
val accessTokenRequest: JsonArrayRequest = object : JsonArrayRequest(
Request.Method.GET, url, JSONArray(),
Response.Listener<JSONArray> {
val json = JSON(it.getString(0))
}, Response.ErrorListener {
if (it.networkResponse != null){
showAlert(this, evaluateErrorCode(it.networkResponse.statusCode).toString())
} else{
showAlert(this, R.string.ERROR_UNKNOWN.toString())
}
// here I want the function to stop (if an error was found)
}) {
@Throws(AuthFailureError::class)
override fun getHeaders(): Map<String, String> {
val params = HashMap<String, String>()
return params
}
}
mQueue.add(accessTokenRequest)
}
}
当Response.ErrorListener捕获某些内容时,我不想执行Response.Listener。我该如何实现?