gpt4 book ai didi

javascript - "restClient is not defined"虽然它实际上是

转载 作者:行者123 更新时间:2023-11-28 05:58:28 26 4
gpt4 key购买 nike

这是我的代码片段

  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)

客户端“像往常一样”在文件开头定义(一直有效),并且它使用 npm 模块restify。我什至不明白问题是否可能是范围界定或其他什么,有没有人对我可以在哪里进行讨论有任何好的建议?

谢谢

更新:我认为这不是范围之类的问题;我怀疑这是与restify有关的问题,因为否则错误将类似于“ReferenceError:restClient未定义”。尽管如此,我还是很茫然,因为它以前可以工作,而且我没有引入任何重大改变来破坏它。 Restify版本为3.0.3

最佳答案

好吧,答案很简单,我觉得很愚蠢(我应该这样做),

由于存在 resterr,断言被触发。它来自使用 restClient.get()

调用的 API 处理程序

但是,我期望整个(其他)程序执行诸如崩溃(在另一个断言上)之类的操作或告诉我ReferenceError:restClient未定义,但分析日志它并没有发生。因此,我认为问题出在此处的代码片段中,而不是在我调用的远程 API 中(仍然由我编写)。

关于javascript - "restClient is not defined"虽然它实际上是,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37467875/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com