[英]@hapi/wreck res.once is not a function when wreck.post
这样做时:
const user={email:'toto@domain.com'};
const apiRes = await Wreck.post('http://localhost:3000/logged-in', {payload: user});
const body = await Wreck.read(apiRes);
console.log({body});
我收到这条消息:
(node:23384) UnhandledPromiseRejectionWarning: TypeError: res.once is not a function
我检查了我的另一台服务器( localhost:3000
),回答是 200 和正文,没关系。
所以我不知道该怎么办。 我的代码基于这个示例: https : //hapi.dev/module/wreck/#advanced而且似乎单元测试也做同样的事情https://github.com/hapijs/wreck/blob/master/test/ index.js#L70
好吧,看来我遇到了最有名的错误,叫做stupidity
工作代码:
const user={email:'toto@domain.com'};
const {payload} = await Wreck.post('http://localhost:3000/logged-in', {payload: user});
console.log({payload});
发布快捷方式是包装请求+读取调用。 像其他快捷方式一样: https : //github.com/hapijs/wreck/blob/master/lib/index.js#L524
感谢 YoannMa,我在 hapi slack 上得到了答案https://hapihour.slack.com/archives/C6BMHNBLM/p1605023760162200?thread_ts=1605022489.160200&cid=C6BMHNBLM
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.