How to read error body sent by server when using Retrofit + Coroutine

When using Coroutine with Retrofit in order to call network apis, in case the server returns an error (response code != 200) we will get an Exception. My question is how to find/read the error body (in Json) sent by the server through the Exception?

try{
     apiService.login()
}catch(exception:Exception){
     //How to read error body from exception
}


Read more here: https://stackoverflow.com/questions/67378400/how-to-read-error-body-sent-by-server-when-using-retrofit-coroutine

Content Attribution

This content was originally published by Ehsan Heidari at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: