JSON.parse is called on invalid json (response from sendEventData)
See original GitHub issueI got the following error on my production server today:
<html>
^
SyntaxError: Unexpected token < in JSON at position 0
at JSON.parse (<anonymous>)
at IncomingMessage.<anonymous> (/app/node_modules/keen-tracking/lib/record-events-server.js:206:22)
The error occurs at /app/node_modules/keen-tracking/lib/record-events-server.js:206:22
where you have: var res = JSON.parse(body), error;
It’s been my experience that you should always wrap any call to JSON.parse
in a try/catch
block.
I’m sure that’s not enough for a fix - seems like the keen server is returning an html body instead of json - so you might have a bigger issue here, and I’m not even sure if I was sending something invalid in my request (because the error, as you can see, cannot be parsed).
Issue Analytics
- State:
- Created 6 years ago
- Comments:12 (6 by maintainers)
Top Results From Across the Web
How to handle invalid JSON parse error properly.
JSON.parse() is a built-in method in JavaScript which is used to parse a JSON string and convert it into a JavaScript object. If...
Read more >How to Fix the Invalid JSON Error in WordPress? - Rank Math
In this article, learn how to fix the invalid JSON error - 'Updating failed. The response is not a valid JSON response.' with...
Read more >How to Fix the Invalid JSON Response Error in WordPress
Learn what's causing the invalid JSON response error on your WordPress site as well as the different ways you can fix it.
Read more >How to check if a string is a valid JSON string? - Stack Overflow
Use a JSON parser like JSON.parse : function isJsonString(str) { try { JSON.parse(str); } catch (e) { return false; } return true; }....
Read more >How to Fix The Invalid JSON Error in WordPress (Beginner's ...
This error appears when editing WordPress posts or pages on your website. You'll see a message saying 'The response is not a valid...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@dustinlarimer Thanks for the expedient patch!
If your eng team needs data to look at, feel free to reach out to me @ daryl@zenrez.com 👍
@joaoreynolds @dlau apologies for the glitch – this patch has been published in
keen-tracking@1.3.0
. Thanks for reporting and helping us squash this bug! Please let me know if you encounter any more issues.I’ve also shared your posts with our platform eng team to investigate those malformed responses 👍