Android Question How to read API result when ls_http.Success = False

sivakrith

Member
Licensed User
Longtime User
Hello,

B4A 11.50

I call API (written in PHP with Slim Framework) which returns value(s) with corresponding status code [=200, = 201, =422, =500 etc. ]. I need to read the result values whatever the return status code is.

API Call:
    ls_httpjob.PostString(Main.gs_url & url,ls_jsonstr)
    wait for (ls_httpjob) jobDone(ls_http As HttpJob)
    
    ls_result = ls_http.GetString
    Log("ls_result: "& ls_result)

When the return status code is 200, ls_result contains the correct return value. [ Even on this error condition, we changed to return status to 200 ].
//ls_result = {"Status":422,"Result":"Failed","Message":"Version does not match"}

When the return status code is 422, ls_result contains some value, don't know where and how it gets.
//ls_result = {"Status":422,"Result":"Failed","Message":"Version value is empty. Pass Version"}
We don't know why this message is read, which is to be returned on another condition.

When checked in Postman, we get the correct values. Only in B4A, we get the above wrong value.

Is there any way to read the correct return value(s) when the return status code is not 200? (Or) How to read return values on ls_http.Success = False?

Happiness Always
BKR Sivaprakash


Log entries

When ls_http.Success = False, we get the below line(s)
ResponseError. Reason: Unprocessable Entity, Response: {"Status":422,"Result":"Failed","Message":"Version does not match"}
ls_result: {"Status":422,"Result":"Failed","Message":"Version value is empty. Pass Version"}

When ls_http.Success = True, we get the below line(s)
ls_result: {"Status":422,"Result":"Failed","Message":"Version does not match"}
 

sivakrith

Member
Licensed User
Longtime User
Hello,

Seems this code gives me the required result. Is this correct approach?

Read Return Values:
If ls_http.Success = True Then
    ls_result = ls_http.GetString
Else
    ls_result = ls_http.Response.ErrorResponse
End If

Happiness Always
BKR Sivaprakash
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…