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

Discussion in 'Android Questions' started by Douglas Farias, Jul 15, 2019.

  1. Douglas Farias

    Douglas Farias Expert Licensed 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
    Code:
    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.

    Code:
    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)
    (success case example)

    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
    Code:
    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
     
  2. DonManfred

    DonManfred Expert Licensed User

    It is not available when job.success is false. At least in some situations.
    I don´t think that there is something you can do.
     
  3. Erel

    Erel Administrator Staff Member Licensed User

    You can use Try / Catch here to catch this error.
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice