const mysql = require('mysql2/promise');
class db {
static async query(sql) {
//console.log(this.pool)
try {
const [rows, fields] = await this.pool.query(sql); always exit in here
return rows;
} catch (error) {
console.error('Error querying the database:', error);
return { error: 'Database query failed', details: error.message };
}
}
static connect() {
const pool = mysql.createPool({
connectionLimit: 10,
host: process.env.DB_HOST,
port: process.env.DB_PORT,
user: process.env.DB_USER,
password: process.env.DB_PASSWORD,
database: process.env.DB_NAME,
})
return pool
}
}
why my code alway exit in try catch block , I can’t understand . I thought the error would be catched in the Try Catch block , actually it was not , this confused me .