Skip to content

Conversation

@Alearner12
Copy link

When the WebsiteCarbon API is protected by Cloudflare and requests originate from datacenter IPs, Cloudflare may return an HTML challenge page instead of JSON. This caused JSON.parse() to throw an uncaught SyntaxError exception, crashing the entire application.

This fix:

  • Checks if the response starts with HTML markers before parsing
  • Wraps JSON.parse in try-catch for additional safety
  • Returns a descriptive error message instead of crashing

Fixes #268

When the WebsiteCarbon API is protected by Cloudflare and requests
originate from datacenter IPs, Cloudflare may return an HTML challenge
page instead of JSON. This caused JSON.parse() to throw an uncaught
SyntaxError exception, crashing the entire application.

This fix:
- Checks if the response starts with HTML markers before parsing
- Wraps JSON.parse in try-catch for additional safety
- Returns a descriptive error message instead of crashing

Fixes Lissy93#268
@netlify
Copy link

netlify bot commented Jan 8, 2026

Deploy Preview for web-check ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit a163c35
🔍 Latest deploy log https://app.netlify.com/projects/web-check/deploys/695fdb25570223000808be85
😎 Deploy Preview https://deploy-preview-271--web-check.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Uncaught JSON parsing error in carbon.js when WebsiteCarbon API returns HTML

1 participant