简体   繁体   English

@hapi/wreck res.once 不是 wreck.post 时的函数

[英]@hapi/wreck res.once is not a function when wreck.post

When doing this:这样做时:

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});

I get this message:我收到这条消息:

(node:23384) UnhandledPromiseRejectionWarning: TypeError: res.once is not a function

I checked that my other server ( localhost:3000 ), answers with a 200 and a body, it's ok.我检查了我的另一台服务器( localhost:3000 ),回答是 200 和正文,没关系。

So I don't know what to do.所以我不知道该怎么办。 I based my code on this sample: https://hapi.dev/module/wreck/#advanced And it seems that unit test does the same too https://github.com/hapijs/wreck/blob/master/test/index.js#L70我的代码基于这个示例: https : //hapi.dev/module/wreck/#advanced而且似乎单元测试也做同样的事情https://github.com/hapijs/wreck/blob/master/test/ index.js#L70

  • node version : 12.18.3节点版本:12.18.3
  • module version : @hapi/wreck@17.0.0模块版本:@hapi/wreck@17.0.0

Ok, it seems that i met the most known bug called stupidity好吧,看来我遇到了最有名的错误,叫做stupidity

Working code:工作代码:

const user={email:'toto@domain.com'};
const {payload} = await Wreck.post('http://localhost:3000/logged-in', {payload: user});
console.log({payload});

post shortcut is wrapping request+read calls.发布快捷方式是包装请求+读取调用。 Like others shortcuts : https://github.com/hapijs/wreck/blob/master/lib/index.js#L524像其他快捷方式一样: https : //github.com/hapijs/wreck/blob/master/lib/index.js#L524

Thanks to YoannMa, i got the answer on hapi slack https://hapihour.slack.com/archives/C6BMHNBLM/p1605023760162200?thread_ts=1605022489.160200&cid=C6BMHNBLM感谢 YoannMa,我在 hapi slack 上得到了答案https://hapihour.slack.com/archives/C6BMHNBLM/p1605023760162200?thread_ts=1605022489.160200&cid=C6BMHNBLM

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM