#5878 - FiscalData validations #1851

Merged
carlossa merged 58 commits from 5858-fiscalData-validations into dev 2024-02-28 13:53:34 +00:00
1 changed files with 5 additions and 23 deletions
Showing only changes of commit 62ccbb3074 - Show all commits

View File

@ -1,14 +1,7 @@
const SalixError = require('vn-loopback/util/salixError');
const UserError = require('vn-loopback/util/user-error');
const SalixError = require('../../util/salixError');
const UserError = require('../../util/user-error');
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() {
return function(err, req, res, next) {
// Thrown user errors
@ -18,19 +11,7 @@ module.exports = function() {
}
// Validation errors
if ([400, 422].includes(err.statusCode)) {
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) {
}
if (err.statusCode == 422) {
try {
let code;
let {messages} = err.details;
@ -45,6 +26,7 @@ module.exports = function() {
return next(new UserError(req.__(err.sqlMessage)));
// Logs error to console
let env = process.env.NODE_ENV;
let useCustomLogging = env && env != 'development' &&
(!err.statusCode || err.statusCode >= 500);