[英]How to properly handle SequelizeConnectionError in nodejs
下面的代碼檢查即將通過的連接是否已通過身份驗證
..............
..............
sequelize
.authenticate()
.then(() => {
console.log('Connection has been established successfully.');
})
.catch(err => {
console.error('Unable to connect to the database:', err);
});
....................
.....................
上面的連接過程僅在命令提示符下顯示“錯誤”,而沒有響應用戶。 如何響應客戶端(連接錯誤)?
不確定最流行或最好學習的內容,expressjs網站您好,世界示例是關於響應“ /”路徑“ get” http請求的。
在您的Web應用程序示例代碼中,並使用express.js,您可能正在檢查每個請求的數據庫連接的續集,在這種情況下,您將執行以下操作:
app.get('/', function(res, req) {
sequelize
.authenticate()
.then(() => {
console.log('Connection has been established successfully.');
//and do something like
//send data to the client
})
.catch(err => {
console.error('Unable to connect to the database:', err);
//
res.send('Unable to connect to the database.');
});
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.