This commit is contained in:
parent
f3f0360059
commit
62ccbb3074
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue