我有一个基于node.js的express-server,它应该处理一些数据库操作。目前,我尝试根据提供的电子邮件获取我的SQL数据库的一些信息。在执行下面的操作时,我遇到了一个奇怪的错误。
app.get("/character/:account_email", jsonparser, (req, res) => {
database.query("SELECT account_email, character_name, creation_date, blood, money, experience_points, age, is_alive, place_name FROM vmpr_character WHERE account_email = ?", [req.params.account_email], (error, response, fields) => {
res.set({ "Content-Type": "application/json" });
if (!error) {
res.status(201);
res.write(JSON.stringify(response[0]));
database.query("SELECT attribute_name, level FROM character_attributes JOIN vmpr_character USING (account_email) WHERE character_attributes.account_email = ?", [req.params.account_email], (error2, response2, fields2) => {
if (!error2) {
res.write(JSON.stringify(response2));
} else {
res.status(502);
}
});
} else {
res.status(404);
res.write(JSON.stringify(dummy));
}
res.end();
});
});
TypeError: Cannot read property 'Symbol(asyncId)' of null
at write_ (_http_outgoing.js:636:24)
at ServerResponse.write (_http_outgoing.js:630:10)
at Query.database.query [as _callback] (/Users/nightmare/vmpr/components/database_server/NodeJS/server.js:103:10)
at Query.Sequence.end (/Users/nightmare/vmpr/components/database_server/NodeJS/node_modules/mysql/lib/protocol/sequences/Sequence.js:86:24)
at Query._handleFinalResultPacket (/Users/nightmare/vmpr/components/database_server/NodeJS/node_modules/mysql/lib/protocol/sequences/Query.js:137:8)
at Query.EofPacket (/Users/nightmare/vmpr/components/database_server/NodeJS/node_modules/mysql/lib/protocol/sequences/Query.js:121:8)
at Protocol._parsePacket (/Users/nightmare/vmpr/components/database_server/NodeJS/node_modules/mysql/lib/protocol/Protocol.js:280:23)
at Parser.write (/Users/nightmare/vmpr/components/database_server/NodeJS/node_modules/mysql/lib/protocol/Parser.js:75:12)
at Protocol.write (/Users/nightmare/vmpr/components/database_server/NodeJS/node_modules/mysql/lib/protocol/Protocol.js:39:16)
at Socket.<anonymous> (/Users/nightmare/vmpr/components/database_server/NodeJS/node_modules/mysql/lib/Connection.js:103:28)
将一些数据发布到同一个数据库时会出现同样的错误。即使所提供的数据仍然正常保存,服务器也会在POST和GET上崩溃。在mysql中直接执行这些查询会得到正确的结果。所有日志都很好。
编辑: *使用提供的更新,错误消失,新错误要好得多处理。 *现在一切都很好。谢谢!