I have a problem calling a web service, to retrieve the value of message in case of trouble.
If the return of the call is good, job1.Getstring is ok (I can retrieve my token)
If the return is Bad Request, job1.Getstring is not initialised and I get this error:
java.io.FileNotFoundException: /data/user/0/XXXXXX.V1/cache/1: open failed: ENOENT (No such file or directory)
In the same time, in my log screen, I can see this:
** Service (httputils2service) Create **
** Service (httputils2service) Start **
{
"message": "Invalid login / password or no rights on this activity."
Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("Intro")
Dim URL As String = "http://xxxxxxxxxxxxxxxx.com/wsapi/api/common/auth/login/"
Dim M1 As Map
M1.Initialize
M1.Put("username","User1")
M1.Put("password","Pwd1")
M1.Put("activity",40)
Dim JSONGenerator As JSONGenerator
JSONGenerator.Initialize(M1)
Log(JSONGenerator.ToPrettyString(2))
Dim Job As HttpJob
Job.Initialize("Intro", "Main")
Job.PostString (URL, JSONGenerator.ToPrettyString(2))
Job.GetRequest.SetContentType("application/json")
End Sub
Sub JobDone(Job1 As HttpJob)
Msgbox(Job1.GetString,"")
Job1.Release
End Sub
job.errormessage will return "Bad Request" and not the message handle by the web service like this one: "message": "Invalid login / password or no rights on this activity."
Yes I confirm that (Bad Request) is set in the return of my web service.
here is a part of my dotnet code:
B4X:
If token Is Nothing OrElse String.IsNullOrWhiteSpace(token.Token) Then
Return Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Invalid login / password or no rights on this activity.")
End If
But even if I use another type of return (ambigous, Forbidden,.....) job.getstring is empty and doesn't take care of my message. It's only when return is OK that job.getstring is filled.
More than this, please see the png attached and you will see that my expected message is in the log view. But how to catch it ???
Use OkHttpUtils2 source code instead of the library and change hc_ResponseError to:
B4X:
Sub hc_ResponseError (Response As OkHttpResponse, Reason As String, StatusCode As Int, TaskId As Int)
If Response <> Null Then
Log(Response.ErrorResponse)
Response.Release
CompleteJob(TaskId, False, Response.ErrorResponse)
Else
CompleteJob(TaskId, False, Reason)
End If
End Sub
The full error message will be stored in Job.ErrorMessage.
Thanks for your answer.
Unfortunately, I don't know where to find the source code for OkHttpUtils2 in the forum ....
I just find the .jar file
Could you please help ?
While the answer may seem obvious to some, we must admit that sometimes it may not be clear to others.
We are not all experts.
BE UNDERSTANDING IS THE PREROGATIVE OF THE BEST .....