web-check icon indicating copy to clipboard operation
web-check copied to clipboard

fix: handle non-JSON responses in carbon.js to prevent crash

Open Alearner12 opened this issue 10 months ago • 1 comments

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

Alearner12 avatar Jan 08 '26 16:01 Alearner12

Deploy Preview for web-check ready!

Built without sensitive environment variables

Name Link
Latest commit a163c356b91129a2b9c6233be2f9364398220ee5
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.

netlify avatar Jan 08 '26 16:01 netlify