Randomly failed because of JSON::ParserError : 822: unexpected token - json

I have a REST POST API that receives json data and validates parameters. In the production environment, the API sometimes raises an exception:
JSON::ParserError : 822: unexpected token at ...
The stack trace is like:
> .../gems/ruby-2.2.10/gems/json-1.8.6/lib/json/common.rb:155:in `parse'
> .../gems/ruby-2.2.10/gems/json-1.8.6/lib/json/common.rb:155:in `parse'
> .../gems/ruby-2.2.10/gems/activesupport-4.2.10/lib/active_support/json/decoding.rb:26:in `decode'
It seems that the error occurs randomly; I cannot find any pattern.
When I try the same code with the dumped data, there is no parsing error.
I thought the error is due to running in concurrent, but I tried it in local with 1000 concurrent requests, which are far more than in the production environment, and it still works without any error.
I appreciate to throw some light.
What does the 822 mean in the error message? It does not seem to be the character position in the json data.

Related

SyntaxError: Unexpected token X in JSON at position Y

So I have a function that its sole purpose is to parse JSON's that get dynamically generated but not by my program. Sometimes those JSON's might not meet the proper syntax for a variety of reasons raging from network lag to simply broken json structures. To parse a JSON I use
try { JSON.parse(LARGE_JSON) } catch(e) { .. log the error }
For some reason now, after many parses it seems like my nodejs is leaking and finally encoutering an syntax error
SyntaxError: Unexpected token X in JSON at position 19837
at JSON.parse (<anonymous>)
at Pipe.channel.onread (internal/child_process.js:470:28)
That error crashes the whole process with it, even though I am using try catch. So I really don't understand how to tackle neither the memory leak nor the crashing process, what might the issue be?

Autodesk Forge - Invalid Request URI

recently I ran into an error every time I try to access the Autodesk Forge API. I haven't made any changes to my code but since last week the line of code shown below throws an error.
var content = (StreamContent)client.GetAsync(url).Result.Content;
The error text is as follows.
An invalid request URI was provided. The request URI must either be an absolute URI or BaseAddress must be set.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.InvalidOperationException: An invalid request URI was provided. The request URI must either be an absolute URI or BaseAddress must be set.
I did some testing and it looks like the following line of code returns 'null'.
var url = wi.Arguments.OutputArguments.First(a => a.Name == "Results").Resource;
So the problem seems to be that my work item is not running properly and not returning a valid output.
My code is very similar to the samples provided by Autodesk and as I said my program was working fine up until last week so I am hoping that someone can help me figure out what is causing this issue.

Json codes 1050 1100 and 1000

I'm trying to understand what kind of error codes I'm getting when I request a page that outputs a json application (I'm integrating a forecast script on my website from another website that provides this service)
When I request the json application at http://www.blabla.com/api/get?id=xxxxx&auth=(hash)
I get this error message:
{
"Message":"Bad request","Code":1050
}
What is this kind of error codes? I also got "Invalid input" and code: 1000 when I don't enter the authcode. Have anyone seen these message codes? What are the other code messages?
(I can't provide the website that provides the service because I risque being shut down)
JSON is only a "way of write data", it doesn't define error codes.
The errors you are getting are application-specific. In order to understand those code errors, you should look up into the documentation of "www.blabla.com"

VM892:1 Uncaught SyntaxError: Unexpected token e in JSON at position 0

I'm presently working on a phx / phoenix API written in Elixir. And I have created a frontend for the API using React.js. However, I'm getting the below error message in the JS console of the browser.
I have successfully created a user using Postman, so I'm 99% sure the error isn't with the phx project, but rather somewhere with the React project.
I have both the frontend and backend hosted on github. And a .env file will need to be created in the root of the React project with the below line,
REACT_APP_API_URL=http://localhost:4000/api
and was working my way through the following tutorial.
Any and all help would greatly be appreciated.
The output of localStorage.getItem("token") being
eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJhdWQiOiJVc2VyOjEiLC‌​JleHAiOjE0ODcyODI4OD‌​csImlhdCI6MTQ4NDY5MD‌​g4NywiaXNzIjoiUGhvZW‌​5peENoYXQiLCJqdGkiOi‌​IwNzFlYzgwYi0wZmYzLT‌​QyYzgtODA3Mi1kNzViZm‌​VhZTg4NWEiLCJwZW0iOn‌​t9LCJzdWIiOiJVc2VyOj‌​EiLCJ0eXAiOiJhY2Nlc3‌​MifQ.NsuqH50HooK8vjF‌​fHtPH9iXSykZ9oYA0ul4‌​b_C5fQtpu_zFvNNy-skc‌​v9HI2i25X-NlB-9xOr-x‌​zh2abnrpYUw
suggests that for some reason, the app stored the token without passing it through JSON.stringify, and calling JSON.parse on this string throws the Unexpected token e error, as expected.
I did not see any localStorage.setItem without JSON.stringify in the current code, so the token was probably stored like that in a previous version of the app. You should try clearing it manually and logging in again.
When we get the non-JSON response, we get such error..
To avoid such error, mention the responseType: Text in your api endpoint call.
This will work,
return this.http.post(`${environment.apiUrl}/login`, user, {responseType: 'text'});
This will not work(If you mention type),
return this.http.post<string>(`${environment.apiUrl}/login`, user, {responseType: 'text'});
This error message usually means you're getting a non-JSON response. If you look at the raw response in the Network tab of your debugger, you should be able to see what you're getting back from the server.

Exception java.lang.StringIndexOutOfBoundsException in REST JSON Grails

I used the plugin "JSON RESTful API for GORM" for Grails and I have the next exception:
Error 500: Internal Server Error
java.lang.StringIndexOutOfBoundsException
Message
String index out of range: -1
Around line 64 of JSONDomainMarshaller.groovy
But this only happens when my class domain has a reference to another class domain, the other simple class domain runs perfect.
I hope you can help.