fix: patch CLOB client JSON.stringify to handle circular proxy agent

The CLOB client errorHandling function does JSON.stringify on
err.response.config which includes httpsAgent (HttpsProxyAgent with
circular references). Inject a safe serializer that strips agent
properties before serializing.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
direkturcrypto
2026-03-28 12:16:46 +07:00
parent 0886938694
commit e9e5d66ac9
+13
View File
@@ -66,6 +66,11 @@ axios_1.default.interceptors.request.use(function(cfg) {
}
return cfg;
});
// Safe JSON.stringify that strips circular agent refs
const _safeStringify = (obj) => JSON.stringify(obj, (key, val) => {
if (key === 'httpsAgent' || key === 'httpAgent' || key === 'agent') return undefined;
return val;
});
// ── End proxy patch ────────────────────────────────────────────────────────
`;
@@ -95,5 +100,13 @@ if (!injected) {
process.exit(0);
}
// ── Patch errorHandling to avoid circular JSON serialization ────────────────
// The CLOB client does JSON.stringify(err.response.config) which includes
// httpsAgent with circular references. Replace with safe serializer.
const jsonCount = (code.match(/JSON\.stringify\(/g) || []).length;
code = code.replace(/JSON\.stringify\(/g, '_safeStringify(');
const patchedCount = (code.match(/_safeStringify\(/g) || []).length;
console.log(`[patch] Replaced ${jsonCount} JSON.stringify calls with safe serializer`);
fs.writeFileSync(TARGET, code, 'utf8');
console.log('[patch] @polymarket/clob-client patched with proxy support ✅');