JSON.parse: bad control character in string literal at line 1 column 123 of the JSON data
Seems to happen whenever the description contains a newline, I think there are other control characters you can do (like tabs) which break most JSON parsers.
I’m using node.js with a library called phin which has an option to automatically parse JSON for requests. It was giving me trouble a couple of days ago by failing to parse it.
It doesn’t seem to be doing it anymore though. I’m kinda confused. I tested with both request-promise and phin and used JSON.parse and It’s working correctly now.
EDIT: I delved deeper into the situation by using a bare bones request module. I have concluded that it is not the fact the JSON is invalid, but that API has the chance to return a non-JSON error message:
This id failed: 337208324
This is the web response: The custom error module does not recognize this error.
This was the error: SyntaxError: Unexpected token T in JSON at position 0
at JSON.parse (<anonymous>)
at getSalesFromAssetIds (C:\Users\Jacob\Downloads\clothing-express(1)\clothing-express\api\catalog.js:50:29)
at processTicksAndRejections (internal/process/task_queues.js:93:5)
at async Object.getTotalSalesFromId (C:\Users\Jacob\Downloads\clothing-express(1)\clothing-express\api\catalog.js:66:22)
at async Promise.all (index 0)
at async C:\Users\Jacob\Downloads\clothing-express(1)\clothing-express\main.js:25:30
The custom error module does not recognize this error. is the culprit here, no idea why the API returns that sometimes - I am requesting it extremely fast so that could be the issue why.
Yeah that seems to be the case, the status code is 429 - Too many requests.