-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
can't handle db connection error #1
Comments
node-mysql-query-promise works together with the config module. module.exports = {
database: {
'master': {
host: 'localhost',
user: 'username',
password: 'password',
port: '3306',
database: 'database',
connectionLimit: 10
},
'slave': {
host: 'localhost',
user: 'username',
password: 'password',
port: '3306',
database: 'database',
connectionLimit: 10
}
}
}; Edit this file for your settings. Вот пример использования: var query = require('mysql-query-promise'),
qs = 'SELECT * FROM foo WHERE bar=?';
query(qs, ['baz'], 'master')
.then(function(rows){
/* Do what you need with query results here */
}, function(err){
/* Errors handler */
}); Note that the function has 3 arguments: Edit your example: // ...
const q = query(`SELECT * from ${tableName}`, [], 'master')
// ... or // ...
const q = query(`SELECT * from ?`, [tableName], 'master')
// ... |
I know how to configure |
Try: try {
let rows = await q
} catch (err) {
console.log("Error!")
} |
no, error still not catching! |
Unfortunately I do not have the opportunity to quickly fix this problem, because the error occurs in the mysql-query module, which is written in the callback style. That's why koa can not catch this error. We can fix this error in the following releases. |
I'm using
mysql-query-promise
with koa. When mysql has failed to connect to db, nodejs has been exited.I want to handle connection error, so i tried to handle error on
koa middleware
(see below),koa event
handler and onmysql-query-promise
promise catch handler (see below), but any of this both methods not executes on connection error and node has falled.How can i handle
mysql-query-promise
connection error?The text was updated successfully, but these errors were encountered: