I have implemented a simple POST request for login API.
val fuelRequest = Fuel.post(urlString)
.header("Content-Type", "application/json")
.header("Accept", "application/json")
.jsonBody(UtilsString.getStringForDictionary(params))
fuelRequest.response() { _, response, result ->
...
callback.onComplete(result)
}
When the response is ok, there is no problem. The problem occurs when I try to get the data response from an error request. The data that I get is this :
{
"code": 401,
"error": "The specified credentials are invalid."
}
And this comes with a 401 Unauthorised response. I've just wanted to get the message from de request. If I try response.data it throws Method threw 'java.io.IOException If I try result.component()2.response it throws Method threw 'android.os.NetworkOnMainThreadException' exception. Cannot evaluate com.github.kittinunf.fuel.core.Response.toString() If I try result.error.errorData it throws Method threw 'java.io.IOException
Any clue how can I get the response?
I couldn't add code snippet in the comment but here is the code snippet. You could take the request something like this and do whatever you want according to your usecase.