Closed rajeshdalsaniya closed 5 years ago
Before, we would eagerly load the body response if it were an error. This consumed a lot of data on large error messages even if they were not used.
Now it only reads the error message once you ask for it (.read / .data / etc ).
Your exception is that you're doing this on the main thread. We can probably come up with a better solution for you here, but a temporary workaround would be to use a thread/coroutine/non main thread execution for reading the error message
Before, we would eagerly load the body response if it were an error. This consumed a lot of data on large error messages even if they were not used.
Now it only reads the error message once you ask for it (.read / .data / etc ).
Your exception is that you're doing this on the main thread. We can probably come up with a better solution for you here, but a temporary workaround would be to use a thread/coroutine/non main thread execution for reading the error message
Thanks for your suggesion. I fixed the issue by making change in error handling code. as per below. I changed error handling as doAsync and Error message on uiThread (Note: I am using Anko Library for background task)
result.fold(success = { json ->
callback.onCompleted(ConstantData.APICallJSONResult(json.obj()))
}, failure = { error ->
Log.e("Failure", error.toString())
Log.e("Failure", error.response.statusCode.toString())
// Log.e("Failure", error.message)
doAsync {
try {
val errorMessage = parse(String(error.errorData))?.get("error")
Log.e("Failure - T", errorMessage.toString())
uiThread {
CommonCalls.errorWithMessage(context, errorMessage.toString())
callback.objectStatusUpdate(true)
}
} catch (e: Exception) {
Log.e("Failure - T", e.toString())
} catch (e: FuelError) {
Log.e("Failure - T", e.toString())
}
}
With Previous Version I was successfully getting error response via response.data in code like this
But with latest version of Fuel it not working in android. I tried following code to get error code on Result Failure but it not working. Kindly guide me. Thanks
My json response is when Result Failure with status code 400 or 422
Android Error coming when I try to access - result.component2()?.errorData? or error.errorData
Not I am using Laravel Lumen for API here is Code of Laravel lumen error response code