next(`Str-6ren">
gpt4 book ai didi

javascript - 错误 : Data should not be empty or the "fields" option should be included

转载 作者:行者123 更新时间:2023-11-30 20:06:41 25 4
gpt4 key购买 nike

我有一些看起来像这样的代码

try {
return inputStream
.pipe(JSONStream.stringify())
.on('error', e => next(`Stringify error: ${e}`))
.pipe(Json2csvTransform)
.on('error', e => next(`json2csv error: ${e}`))
.pipe(res)
.on('finish', () => console.log("Streaming of file is now complete."))
} catch(error) {
return res.status(400).json({ message: msg('fileRetrievalError', -3) })
}

当我到达 .on('error', e => next('json2csv error: ${e}'))

这个过程并没有落入catch,它只是一直在继续。我猜这是因为它被包裹在 next

我最终能够提取的错误是这样的:

错误:数据不应为空或应包含“字段”选项

我试图挖掘 Node 模块中的源代码,但这对我来说意义不大。

我想我有两种可能的解决方案:要么我需要了解来自 Json2csv 的错误的含义,要么我需要能够退出并关闭我的流。我试图将 return res.status(400).json({ message: msg('fileRetrievalError', -3) }) 插入 .on('error; ),但如果进程失败一次,则每次都会失败,直到 session 结束,即使提供了所有有效信息 - 如果这有意义的话。

我对 Node 知之甚少,而且这个包也没有很多围绕它的支持。

最佳答案

如果你想在处理一个特定的错误后停止处理流,你必须抛出错误:

.on('error', e => throw error.message)

关于javascript - 错误 : Data should not be empty or the "fields" option should be included,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52847069/

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