Android Question How to get JSON error text ?

b4auser1

Well-Known Member
Licensed User
Longtime User
I tried to get JSON error text using Job.GetString

If Job.Success = False Then
Dim ErrorText As String = Job.GetString
but some errors b4a raises exception about misssing cache file
for others returns text, but not with error data.

I can still see in the log error text like below. As far I understand the text is logged by internal proc inside Httputils2 framework.

{
"error" : "invalid_grant",
"error_description" : "Code was already redeemed."
}

How to correct the problem ?
 

DonManfred

Expert
Licensed User
Longtime User
{
"error" : "invalid_grant",
"error_description" : "Code was already redeemed."
}
Are you reusing the AUTH-code? Or did you get a fresh auth code before sending the request. looks like an auth-code can only be used once. For future requests you need to get a new one i believe.
 
Upvote 0

b4auser1

Well-Known Member
Licensed User
Longtime User
Are you reusing the AUTH-code? Or did you get a fresh auth code before sending the request. looks like an auth-code can only be used once. For future requests you need to get a new one i believe.
Thank you for fast response.

I don't have a problem to get correct access token. But I want to process situations, if an error is returned.
In order to process exceptions, I need to get data describing the error. Rest API returns the data as a JSON object. Now I can't get this JSON object - details in my previous message.
 
Upvote 0

b4auser1

Well-Known Member
Licensed User
Longtime User
B4X:
Dim parser As JSONParser
parser.Initialize(your json string here)
Dim root As Map = parser.NextObject
Dim error As String = root.Get("error")
Dim error_description As String = root.Get("error_description")

Httputils2 framework works incorrectly and Job.GetString doesn't return correct text with JSON data.

For some errors, b4a raises exception about misssing cache file, for others it returns text, but not with correct JSON error data.

It's necessary to fix something to support correct text returned with Job.GetString if Job.Success = False.
 
Upvote 0
Top