0

I am trying to handle the error of mysql query for deleting.

`

When the error is occurring, instead of executing the response function MySQL is throwing the error in the console and stopping the server.

`

This used to work before, but now it is not working now.

Is this because of any version of MySQL and nodejs??

.

I am using node js version: v10.6.0.

MySQL connector version: ^2.16.0.

.

I have created a relationship between two tables with restricting delete.

.

This is my code to delete an item from the table.

this.deletePurchaseBill = function (id) {
    return new Promise(function (resolve, reject) {
        var delete_purchase_bill_sql = `DELETE FROM purchase_entry_header WHERE id = '${id}'`;
        conn.query(delete_purchase_bill_sql, function (err, result) {
            console.log('error:' + err);
            if (err) {
                if (err.errno == 1451) {
                    resolve({
                        status: "error",
                        message: "This purchase can not be deleted",
                        debug: err,
                    });
                } else {
                    resolve({
                        status: "error",
                        message: "Unexpected error occurred",
                        debug: err
                    });
                }
            } else {
                resolve({
                    status: "success",
                    message: "Successfully Deleted"
                });
            }
        });
    });
};

.

Any help would be appriceated

Hello World
  • 2,673
  • 7
  • 28
  • 60
  • Why haven't you rejected in case of the error? – Siraj Alam Jul 31 '20 at 09:59
  • @SirajAlam didn't do that because I need to show the error to the end-user. Is that why the server is crashing? – Hello World Jul 31 '20 at 12:48
  • @HelloWorld as far as I know even though mySql will throw an error because of node js non-blocking method, the server wont stop. it will only not return the error to the end-user – meBe Aug 06 '20 at 17:00
  • @Ji-Yong this used to work before without any problem, but from few days I have been getting this issue. – Hello World Aug 06 '20 at 18:31

0 Answers0