Android Question Get body even with a response with error. okHttp

Douglas Farias

Expert
Licensed User
Longtime User
Hello everyone.
I'm building an application and unfortunately I do not have server side access.

I need to get the response from the server even if it returns me an error in okHttp

example
B4X:
    If j.Success Then
        Log("success")
        Log(j.GetString)
    Else
        Log("error")
        Log(j.ErrorMessage)
        Log(j.GetString)
    End If


Sometimes i will get log success and sometimes i got error.
but when i get the error, the j.GetString is the same of the success response.

B4X:
    If j.Success Then
        Log(j.GetString) 'WORKS FINE, I GOT THE SOAP XML RESPONSE, ALL WORKING FINE
    Else
        Log(j.GetString) 'WORKS FINE, I GOT THE SOAP XML RESPONSE, ALL WORKING FINE (ON MY DEVICE)
    End If


this code above works fine on my device, MI A2 Lite with Android 9
but on old devices it crash on j.GetString

Obs: runing the code above on my device i got this logs

(error case example)
- error
- javax.net.ssl.SSLException: Read error: ssl=0x75f489c188: I/O error during system call, Connection reset by peer
- the response in xml

(success case example)
- success
- the response in xml


On the old Android Versions, or another devices i got a crash in j.GetString when the case is Error.

Crash on this line on httpJob Class
B4X:
tr.Initialize2(File.OpenInput(HttpUtils2Service.TempFolder, taskId), Encoding)


the question is, how can I get the body of the error, regardless if the response from httpjob is successful or not ..

what modifications should I make in the HttpUtils2Service class?

remembering: I do not want to get the error log, or know what error occurred, I need is the return of the job, job.getstring ....


Thx All
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…