node.js - NODEJS - 即使成功完成,从另一个端点调用一个端点也会陷入 CATCH
问题描述
我有这两个端点(它被简化了,但想法/问题保持不变)......
/api/v1/更新
exports.update = (req, res) => {
Data.update({salary: 1})
.then(data => {
console.log("All good")
return res.status(200).send({message: "OK"})
})
.catch(error => {
console.log("Oh Crap!")
return res.status(400).send(error)
})
}
和
/api/v1/process我在其中调用第一个作为处理的一部分
exports.process = (req, res) => {
axios.get('http://localhost:8008/api/v1/update')
.then(data => {
console.log("You got it")
return res.status(200).send(data)
})
.catch(error => {
console.log("Not working!")
return res.status(400).send(error)
})
}
这就是我在控制台中得到的:
$>: nodemon server.js
Server running on port 8008
All good
Not working!
为什么 axios 调用成功(“更新”端点)完成但它落入 CATCH 而不是 THEN ?
我错过了什么?
编辑:
好的,我想通了..错误在return res.status(200).send(data)
/api/v1/process ...
错误:将循环结构转换为 JSON
所以我所做的是我提取了值(第一个端点的响应->更新)并在之后发送它:)它现在工作得很好......愚蠢的错误
掌心
解决方案
错误出现在 /api/v1/process 的返回 res.status(200).send(data) ...
错误:将循环结构转换为 JSON
所以我所做的是我提取了值(第一个端点的响应->更新)并在之后发送它:)它现在工作得很好......愚蠢的错误
推荐阅读
- docker - ChromeHeadless 在管道内失败,但在本地失败
- r - 在R group by function中使用过滤器子句
- c# - 如何使用 Visual Studio 在 Xamarin.Forms 中更改我的应用程序图标?
- angular - 如何根据 ngxPermissions 使 p-calender 启用/禁用
- regex - 需要帮助使用 sed 停止将 \n 解释为 linux bash 脚本中的新行
- tensorflow - keras.datasets.mnist 和 tensorflow.examples.tutorials.mnist 有什么区别?
- full-text-search - wikidata API 中 wbsearchentities 的准确性
- javascript - 如何将选定的 HTML 表格行值显示到 div 中以用于图像
- php - 设置 Joomla 自定义 404 页面时遇到问题,该页面还返回 404 代码而不是 200(不重复)
- .net - Windows 窗体应用程序包括 .net 框架