Commit a163c35
Sid
fix: handle non-JSON responses in carbon.js to prevent crash
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 #2681 parent 4b4bf20 commit a163c35
1 file changed
Lines changed: 11 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
29 | 29 | | |
30 | 30 | | |
31 | 31 | | |
32 | | - | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
33 | 43 | | |
34 | 44 | | |
35 | 45 | | |
| |||
0 commit comments