Kay*_*Kay 5 node.js express node-request request-promise
我正在使用请求库进行外部api调用.https://github.com/request/request.我正在使用本机promise/async扩展.https://github.com/request/request-promise-native.
但是我无法检查状态代码,它是未定义的.
public async session(): Promise<any> {
const url = <removed>;
const options = {
uri: url,
headers: {
'Authorization': this.config.token
},
json: true,
body: {
}
}
try {
const res = await request.post(options);
if (res.statusCode !== 200) {
// do something
}
console.log(res);
console.log("statuscode", res.statusCode)
return res;
} catch (err) {
return err;
}
}
Run Code Online (Sandbox Code Playgroud)
res.statusCode未定义.
Kay*_*Kay 15
根据我们需要在选项中定义的文档,我们希望返回完整的响应.
https://github.com/request/request-promise#get-the-full-response-instead-of-just-the-body
const options = {
resolveWithFullResponse: true
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
8405 次 |
| 最近记录: |