Company logo
  • Jobs
  • Bootcamp
  • About Us
  • For professionals
    • Home
    • Jobs
    • Courses
    • Questions
    • Teachers
    • Bootcamp
  • For business
    • Home
    • Our process
    • Plans
    • Assessments
    • Payroll
    • Blog
    • Sales
    • Calculator

0

48
Views
How to catch Mysql query errors?

I have this:

const connector = mysql.createPool({
  connectionLimit: 20,
  host: "127.0.0.1",
  database: "todo",
  user: "root",
  password: "password",
});

executes :

const execute = async (query: string) => {
  try {
    const rows = await connector.query(query);
    console.log("done", rows);
    return rows;
  } catch (err) {
    // ERROR NEVER HERE --- WHY?
    console.log("DB ERROR => " + err);
    return err;
  }
};

export default execute;

calling:

execute("INSERT INTO tablename (column1) VALUES('hello')")

I had a typo when doing an INSERT and could not understand what was going wrong before I console logged the flow. I expected that query would throw the error to my catch but for some reason it never did, why?

7 months ago ยท Juan Pablo Isaza
Answer question
Find remote jobs