From a5d1c68511060e930ec2a802542ec591913c728c Mon Sep 17 00:00:00 2001 From: carlossa Date: Mon, 17 Jul 2023 14:07:45 +0200 Subject: [PATCH] change err and traduction --- loopback/locale/es.json | 3 ++- modules/invoiceIn/back/models/invoice-in.js | 8 ++++++++ modules/invoiceIn/back/models/invoiceInVehicle.js | 1 + 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/loopback/locale/es.json b/loopback/locale/es.json index 4086cfa4a..08f5bf765 100644 --- a/loopback/locale/es.json +++ b/loopback/locale/es.json @@ -305,5 +305,6 @@ "The renew period has not been exceeded": "El periodo de renovación no ha sido superado", "Valid priorities": "Prioridades válidas: %d", "Negative basis of tickets": "Base negativa para los tickets: {{ticketsIds}}", - "You cannot assign/remove an alias that you are not assigned to": "No puede asignar/eliminar un alias que no tenga asignado" + "You cannot assign/remove an alias that you are not assigned to": "No puede asignar/eliminar un alias que no tenga asignado", + "This invoice has a linked vehicle.": "Esta factura tiene un vehiculo vinculado" } diff --git a/modules/invoiceIn/back/models/invoice-in.js b/modules/invoiceIn/back/models/invoice-in.js index 51905ccb8..0efa6c309 100644 --- a/modules/invoiceIn/back/models/invoice-in.js +++ b/modules/invoiceIn/back/models/invoice-in.js @@ -1,3 +1,5 @@ +const UserError = require('vn-loopback/util/user-error'); + module.exports = Self => { require('../methods/invoice-in/filter')(Self); require('../methods/invoice-in/summary')(Self); @@ -7,4 +9,10 @@ module.exports = Self => { require('../methods/invoice-in/invoiceInPdf')(Self); require('../methods/invoice-in/invoiceInEmail')(Self); require('../methods/invoice-in/getSerial')(Self); + Self.rewriteDbError(function(err) { + console.log(err); + if (err.code === 'ER_ROW_IS_REFERENCED_2') + return new UserError(`This invoice has a linked vehicle.`); + return err; + }); }; diff --git a/modules/invoiceIn/back/models/invoiceInVehicle.js b/modules/invoiceIn/back/models/invoiceInVehicle.js index cf45bf741..7fa780142 100644 --- a/modules/invoiceIn/back/models/invoiceInVehicle.js +++ b/modules/invoiceIn/back/models/invoiceInVehicle.js @@ -2,6 +2,7 @@ let UserError = require('vn-loopback/util/user-error'); module.exports = Self => { Self.rewriteDbError(function(err) { + console.log(err); if (err.code === 'ER_ROW_IS_REFERENCED_2') return new UserError(`This invoice has a linked vehicle.`); return err;