From e06f8fafee94f16dcf4542e5b99198afcaf9580e Mon Sep 17 00:00:00 2001 From: Juan Ferrer Toribio Date: Fri, 28 Apr 2023 20:31:10 +0200 Subject: [PATCH] refs #5541 Constraint fail error ignored --- mylogger.js | 55 ++++++++++++++++++++++++++--------------------- package-lock.json | 4 ++-- package.json | 2 +- 3 files changed, 34 insertions(+), 27 deletions(-) diff --git a/mylogger.js b/mylogger.js index 1926b35..d176d03 100644 --- a/mylogger.js +++ b/mylogger.js @@ -639,31 +639,38 @@ module.exports = class MyLogger { let deleteRow; - if (isDelete) { - [[deleteRow]] = await logInfo.fetchStmt.execute([ - modelName, modelId - ]); - if (deleteRow) - await logInfo.updateStmt.execute([ - originFk, - created, - oldInstance, - modelValue, - deleteRow.id + try { + if (isDelete) { + [[deleteRow]] = await logInfo.fetchStmt.execute([ + modelName, modelId ]); - } - if (!isDelete || !deleteRow) { - await logInfo.addStmt.execute([ - originFk, - row[tableInfo.userField] || null, - action, - created, - modelName, - oldInstance, - newI ? JSON.stringify(newI) : null, - modelId, - modelValue - ]); + if (deleteRow) + await logInfo.updateStmt.execute([ + originFk, + created, + oldInstance, + modelValue, + deleteRow.id + ]); + } + if (!isDelete || !deleteRow) { + await logInfo.addStmt.execute([ + originFk, + row[tableInfo.userField] || null, + action, + created, + modelName, + oldInstance, + newI ? JSON.stringify(newI) : null, + modelId, + modelValue + ]); + } + } catch (err) { + if (err.code == 'ER_NO_REFERENCED_ROW_2') { + this.debug('Log', `Ignored because of constraint failed.`); + } else + throw err; } } } diff --git a/package-lock.json b/package-lock.json index a47d138..4037aaa 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "mylogger", - "version": "0.1.11", + "version": "0.1.12", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "mylogger", - "version": "0.1.11", + "version": "0.1.12", "license": "GPL-3.0", "dependencies": { "colors": "^1.4.0", diff --git a/package.json b/package.json index 44b61e3..5f5fd5a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "mylogger", - "version": "0.1.11", + "version": "0.1.12", "author": "Verdnatura Levante SL", "description": "MySQL and MariaDB logger using binary log", "license": "GPL-3.0",