为了进行传出 api 调用,我使用了包装在 bluebird promise 对象中的 restler。但是,我得到了一个Possibly unhandled TypeError: Converting circular structure to JSON
at node_modules/bluebird/js/main/promise.js
。
即使没有 JSON.stringify,也会发生这种情况。它发生在 promise.js 的级别。
我能做些什么呢?
rest.postJson(uri, body).then(
function(response) {
console.log(response.access.token.id);
console.log(response.statusCode);
res.send(response.access.token.id);
}, function(error) {
console.log(error.statusCode);
res.send(JSON.stringify(error));
//res.send(error);
});
Possibly unhandled TypeError: Converting circular structure to JSON
at Object.stringify (native)
at ServerResponse.res.json (/home/one/try/cloudimageshare-monitoring/project/node_modules/express/lib/response.js:205:19)
at ServerResponse.res.send (/home/one/try/cloudimageshare-monitoring/project/node_modules/express/lib/response.js:121:21)
at /home/one/try/cloudimageshare-monitoring/project/app/scripts/proxy/proxies_express_module.js:39:29
at tryCatch1 (/home/one/try/cloudimageshare-monitoring/project/node_modules/bluebird/js/main/util.js:43:21)
at Promise$_callHandler [as _callHandler] (/home/one/try/cloudimageshare-monitoring/project/node_modules/bluebird/js/main/promise.js:627:13)
at Promise$_settlePromiseFromHandler [as _settlePromiseFromHandler] (/home/one/try/cloudimageshare-monitoring/project/node_modules/bluebird/js/main/promise.js:641:18)
at Promise$_settlePromiseAt [as _settlePromiseAt] (/home/one/try/cloudimageshare-monitoring/project/node_modules/bluebird/js/main/promise.js:804:14)
at Promise$_settlePromises [as _settlePromises] (/home/one/try/cloudimageshare-monitoring/project/node_modules/bluebird/js/main/promise.js:938:14)
at Promise$_rejectPromises [as _rejectPromises] (/home/one/try/cloudimageshare-monitoring/project/node_modules/bluebird/js/main/promise.js:931:10)
更新:如果有帮助,这里是错误对象的键:
[ '_readableState',
'readable',
'domain',
'_events',
'_maxListeners',
'socket',
'connection',
'httpVersion',
'complete',
'headers',
'trailers',
'_pendings',
'_pendingIndex',
'url',
'method',
'statusCode',
'client',
'_consuming',
'_dumped',
'httpVersionMajor',
'httpVersionMinor',
'upgrade',
'req',
'pipe',
'addListener',
'on',
'pause',
'resume',
'read',
'rawEncoded',
'raw' ]