Android Question OKHTTPUtils2 Library Doesn't Return Response

Homerclese

Member
Licensed User
Longtime User
I am using the OKHTTPUtils2 library successfully in my web services consuming app. It works fine except I have a problem when a service fails in that I can't examine the response returned by the service which indicates the reason for the failure.

For example our login/auth service might fail because the user has entered an invalid password or because they've made too many attempts, etc, and I need to explain what went wrong using different language depending on the reason for the failure. The problem seems to be that when Job.Success is set to False, Job.GetString is invalid. Is there a way around this?
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Check the value of Job.ErrorMessage. If it is not the value that you want then you can use OkHttpUtils2 source code instead of the library and change line 54 in HttpUtils2Service from:
B4X:
Log(Response.ErrorResponse)
To:
B4X:
Dim job As HttpJob = TaskIdToJob.Get(TaskId)
job.Tag = Response.ErrorResponse

Now the same error that is printed in the logs will be stored in Job.Tag.
 
Upvote 0

Homerclese

Member
Licensed User
Longtime User
Thanks Erel. Job.ErrorMessage only contains a generic "Not authorized" in my auto example but I need the subtleties of the response packet to properly notify the user. Where can I find the OKHttpUtils2 source code?
 
Upvote 0
Top