Android Question json response conflict

tufanv

Expert
Licensed User
Longtime User
Hello,

I am sending a http request , if the request returns false I need to display a msgbox. PRoblem is this is what i get from the logs :

B4X:
JobName = order, Success = false
{"code":-2010,"msg":"Account has insufficient balance for requested action."}

In my code I am trying to display the msgbox when the job's error message which is: "Account has insufficient balance for requested action."

job.errormessage is not the json for the error message it is empty
when I try job.getstring at success=false section as below ,it is not also working. How can i grab that message to show in msgbox ?

B4X:
If Job.JobName="order" Then
        If Job.Success = True Then
       
     
                Log(Job.GetString)
              
  
        Else
       
   
Dim parser As JSONParser
parser.Initialize(job.getstring)  ' I also tried job.errormessage here
Dim root As Map = parser.NextObject
Dim msg As String = root.Get("msg")
Dim code As Int = root.Get("code")
msgbox(msg,"Error")

   
        End If
    End If
 

OliverA

Expert
Licensed User
if the request returns false
Most likely, the returned information contains the "false" information, but yet still returns a HTTP response code of 200, which means Job.Success is true. HTTP response codes are usually not used for true/false returns. So most likely, even though you get a "false" return, you still have to process that in Job.Success portion of your code. The only time you get Job.Success = False if the HTTP response code is not 200 (https://en.wikipedia.org/wiki/List_of_HTTP_status_codes).
 
Upvote 0
Top