私は約束を使ってmysqlデータを返そうとしていますが、それはうまく動作しますが、mysqlでエラーを作成しようとするとエラーになります。約束の拒否がmysqlエラーで動作しない
(node:28464) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): Users not found
(node:28464) 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.
私はどこにでもチェックし、それは私がキャッチを使用していますが、問題を把握することはできませんことを.catch使用することを言いますが、その奇妙な。通常は、正しい方法を知らずにそのまま続ける代わりに、これを解決する方法を知りたいと思います。
これは
getAllUser =
new Promise((resolve, reject) => {
db.query('SELECT * from users', function (error, results, fields) {
if (error){
return reject('Users not found');
}else{
resolve(results[0]);
}
});
});
module.exports = {
getAllUser
};
そして、ここでは、私はモデルを呼び出していますか..ですモデルであるMySQLのテーブルはuser
ないusers
と呼ばれているので、トップでモデルがエラーを返す必要があります。
router.get('/db',(req,res,next)=>{
getAllUser.then((result)=>{
console.log(result);
}).catch((e) => {
console.log(e);
});
});
試みはその後、私がやった –
@RobertRowntreeを "リターンは拒否" 働かなかった代わりに "拒否"返信しようとしました – FaF
@RobertRowntreeその奇妙な、私は非常に多くの異なる方法を試みたが、それでも同じエラー。 – FaF