【发布时间】:2018-03-12 09:21:12
【问题描述】:
我正在尝试使用 node-request 对存储在 Amazon S3 上的图像进行管道传输。但是,有时图像不存在,S3 将其公开为状态码 403。我正在努力了解如何在成功的情况下进行管道传输(200),但在非 200 的情况下采取替代操作.
使用 abort() 方法似乎是可行的方法,但会得到一个 r.abort is not a function,即使它应该在请求中可用。
// context: inside a request handler, where `res` is the response to write to
const r = request(url)
.on('response', function (response) {
if (response.statusCode !== 200) {
r.abort(); //failing
// I want to stop the piping here and do whatever instead.
}
})
.pipe(res);
想法?
【问题讨论】:
标签: node.js node-request