refs #5858 fix error
gitea/salix/pipeline/pr-dev There was a failure building this commit Details

This commit is contained in:
Carlos Satorres 2024-02-20 13:45:10 +01:00
parent f3f0360059
commit 62ccbb3074
1 changed files with 5 additions and 23 deletions

View File

@ -1,14 +1,7 @@
const SalixError = require('vn-loopback/util/salixError'); const SalixError = require('../../util/salixError');
const UserError = require('vn-loopback/util/user-error'); const UserError = require('../../util/user-error');
const logToConsole = require('strong-error-handler/lib/logger'); const logToConsole = require('strong-error-handler/lib/logger');
const valueIsNot = require('./value-is-not');
const valueInvalid = require('./value-invalid');
const mapMethods = require('vn-loopback/util/map-methods');
const validations = [
valueIsNot,
valueInvalid,
mapMethods
];
module.exports = function() { module.exports = function() {
return function(err, req, res, next) { return function(err, req, res, next) {
// Thrown user errors // Thrown user errors
@ -18,19 +11,7 @@ module.exports = function() {
} }
// Validation errors // Validation errors
if ([400, 422].includes(err.statusCode)) { if (err.statusCode == 422) {
try {
validations.forEach(validation => {
if (validation.validation(err.message)) {
const error = validation.handleError(req, err);
if (error)
err.message = validation.message(error, req);
}
});
return next(err);
} catch (e) {
}
try { try {
let code; let code;
let {messages} = err.details; let {messages} = err.details;
@ -45,6 +26,7 @@ module.exports = function() {
return next(new UserError(req.__(err.sqlMessage))); return next(new UserError(req.__(err.sqlMessage)));
// Logs error to console // Logs error to console
let env = process.env.NODE_ENV; let env = process.env.NODE_ENV;
let useCustomLogging = env && env != 'development' && let useCustomLogging = env && env != 'development' &&
(!err.statusCode || err.statusCode >= 500); (!err.statusCode || err.statusCode >= 500);