We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents 62b3c88 + a163c35 commit aac6121Copy full SHA for aac6121
1 file changed
api/carbon.js
@@ -29,7 +29,17 @@ const carbonHandler = async (url) => {
29
data += chunk;
30
});
31
res.on('end', () => {
32
- resolve(JSON.parse(data));
+ // Check if response looks like HTML (e.g., Cloudflare challenge page)
33
+ const trimmedData = data.trim();
34
+ if (trimmedData.startsWith('<!DOCTYPE') || trimmedData.startsWith('<html') || trimmedData.startsWith('<')) {
35
+ reject(new Error('WebsiteCarbon API returned HTML instead of JSON. This may be due to Cloudflare protection when running from a datacenter IP.'));
36
+ return;
37
+ }
38
+ try {
39
+ resolve(JSON.parse(data));
40
+ } catch (parseError) {
41
+ reject(new Error(`Failed to parse WebsiteCarbon API response as JSON: ${parseError.message}`));
42
43
44
}).on('error', reject);
45
0 commit comments