question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

JSON.parse is called on invalid json (response from sendEventData)

See original GitHub issue

I 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:closed
  • Created 6 years ago
  • Comments:12 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
dlaucommented, Oct 2, 2017

@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 👍

1reaction
dustinlarimercommented, Oct 2, 2017

@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 👍

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found