如何解决我在Postgres中插入或更新时得到Parser.parseErrorMessage
我为此感到头痛,我不明白是什么问题。
这是我在Express中的代码
router.patch("/:id",verifyToken,async (req,res) => {
const { id } = req.params;
const { title,content,categories } = req.body;
const authorId = parseInt(req.user.id);
try {
let postId = parseInt(id);
if (postId < 0)
res.json(
utils.generateError("Something went wrong,try to reload the page.")
);
//Validate post data
const { error } = validatePostData({
title,});
//Is there and error? Let the user know it.
if (error)
res.status(400).json(utils.generateError(error.details[0].message));
const slug = await utils.generateSlug(title);
const summary = await utils.extractSummary(content,240);
const foundImage = await content.match(/!\[.*?\]\((.*?)\)/);
let image = "";
if (foundImage) image = foundImage[1];
const result = await pool.query(
"UPDATE posts SET title=$1,slug=$2,summary=$3,content=$4,image=$5,author=$6,categories=$7 WHERE id=$8",[title,slug,summary,image,authorId,categories,postId]
);
if (result) res.json(result.rows[0]);
else throw "Error on updating result";
} catch (e) {
console.log(e);
res.json(utils.generateError("Something went wrong,try again."));
}
});
但是当我发出补丁请求时,我会在控制台中得到它。
(node:20756) UnhandledPromiseRejectionWarning: error: invalid input syntax for integer: "NaN"
at Parser.parseErrorMessage (/Users/jcmunguia/Desktop/readalot-app/node_modules/pg-protocol/dist/parser.js:278:15)
at Parser.handlePacket (/Users/jcmunguia/Desktop/readalot-app/node_modules/pg-protocol/dist/parser.js:126:29)
at Parser.parse (/Users/jcmunguia/Desktop/readalot-app/node_modules/pg-protocol/dist/parser.js:39:38)
at Socket.<anonymous> (/Users/jcmunguia/Desktop/readalot-app/node_modules/pg-protocol/dist/index.js:8:42)
at Socket.emit (events.js:310:20)
at addChunk (_stream_readable.js:286:12)
at readableAddChunk (_stream_readable.js:268:9)
at Socket.Readable.push (_stream_readable.js:209:10)
at TCP.onStreamRead (internal/stream_base_commons.js:186:23)
(node:20756) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block,or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection,use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:20756) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future,promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
我正在使用Postgres和pg作为节点来处理数据库,奇怪的是该行已在db中更新,但是查询的结果只返回该错误。
有人可以帮我解决这个问题吗?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。