"restClient is not defined"虽然实际上是
"restClient is not defined" although it actually is
这是我的代码片段
console.log("IS RESTCLIENT UNDEFINED?");
console.log(restClient === undefined);
console.log(restClient);
restClient.get(options, function(resterr, restreq, restres, restobj) {
assert.ifError(resterr);
//not important
return next();
});
问题是当它被执行时(它基本上是路由的大部分处理程序,简单的东西,没有什么深奥的)输出如下:
IS RESTCLIENT UNDEFINED?
false
JsonClient {<a lot of stuff describing the client>}
assert.js:327
assert.ifError = function(err) { if (err) throw err; };
^
InternalError: restClient is not defined
at parseResponse (/srv/oms-profiles-module/node_modules/restify/lib/clients/json_client.js:67:23)
at IncomingMessage.done (/srv/oms-profiles-module/node_modules/restify/lib/clients/string_client.js:151:17)
at IncomingMessage.g (events.js:260:16)
at emitNone (events.js:72:20)
at IncomingMessage.emit (events.js:166:7)
at endReadableNT (_stream_readable.js:893:12)
at doNTCallback2 (node.js:430:9)
at process._tickCallback (node.js:344:17)
客户端定义在文件"as usual"的开头(一直有效到现在),它使用npm模块restify。我什至不明白问题可能出在范围界定还是其他什么问题上,有没有人对我可以在哪里努力提出任何好的建议?
谢谢
更新:我想这不是作用域等问题;我怀疑这是 restify 的问题,否则错误会类似于 "ReferenceError: restClient is not defined"。尽管如此,我还是很茫然,因为它之前是可以工作的,而且我没有引入任何重大变化来破坏它。 Restify 版本为 3.0.3
好吧,答案很简单,我觉得自己很蠢(我应该这样),
由于存在 resterr
,断言被触发。它来自使用 restClient.get()
调用的 API 处理程序
然而我期待整个(其他)程序做一些类似崩溃的事情(在另一个断言上)或告诉我 ReferenceError: restClient is not defined
,但分析日志它没有发生。因此,我认为问题出在此处的代码片段中,而不是在我调用的远程 API 中(仍然由我编码)。
这是我的代码片段
console.log("IS RESTCLIENT UNDEFINED?");
console.log(restClient === undefined);
console.log(restClient);
restClient.get(options, function(resterr, restreq, restres, restobj) {
assert.ifError(resterr);
//not important
return next();
});
问题是当它被执行时(它基本上是路由的大部分处理程序,简单的东西,没有什么深奥的)输出如下:
IS RESTCLIENT UNDEFINED?
false
JsonClient {<a lot of stuff describing the client>}
assert.js:327
assert.ifError = function(err) { if (err) throw err; };
^
InternalError: restClient is not defined
at parseResponse (/srv/oms-profiles-module/node_modules/restify/lib/clients/json_client.js:67:23)
at IncomingMessage.done (/srv/oms-profiles-module/node_modules/restify/lib/clients/string_client.js:151:17)
at IncomingMessage.g (events.js:260:16)
at emitNone (events.js:72:20)
at IncomingMessage.emit (events.js:166:7)
at endReadableNT (_stream_readable.js:893:12)
at doNTCallback2 (node.js:430:9)
at process._tickCallback (node.js:344:17)
客户端定义在文件"as usual"的开头(一直有效到现在),它使用npm模块restify。我什至不明白问题可能出在范围界定还是其他什么问题上,有没有人对我可以在哪里努力提出任何好的建议?
谢谢
更新:我想这不是作用域等问题;我怀疑这是 restify 的问题,否则错误会类似于 "ReferenceError: restClient is not defined"。尽管如此,我还是很茫然,因为它之前是可以工作的,而且我没有引入任何重大变化来破坏它。 Restify 版本为 3.0.3
好吧,答案很简单,我觉得自己很蠢(我应该这样),
由于存在 resterr
,断言被触发。它来自使用 restClient.get()
然而我期待整个(其他)程序做一些类似崩溃的事情(在另一个断言上)或告诉我 ReferenceError: restClient is not defined
,但分析日志它没有发生。因此,我认为问题出在此处的代码片段中,而不是在我调用的远程 API 中(仍然由我编码)。