#6613 - Translations should be in back #1908
|
@ -1,10 +1,11 @@
|
|||
const SalixError = require('../../util/salixError');
|
||||
const UserError = require('../../util/user-error');
|
||||
const logToConsole = require('strong-error-handler/lib/logger');
|
||||
|
||||
module.exports = function() {
|
||||
return function(err, req, res, next) {
|
||||
// Thrown user errors
|
||||
if (err instanceof UserError) {
|
||||
if (err instanceof SalixError) {
|
||||
err.message = req.__(err.message, ...err.translateArgs);
|
||||
return next(err);
|
||||
}
|
||||
|
@ -13,7 +14,7 @@ module.exports = function() {
|
|||
if (err.statusCode == 422) {
|
||||
try {
|
||||
let code;
|
||||
let messages = err.details.messages;
|
||||
let {messages} = err.details;
|
||||
for (code in messages) break;
|
||||
err.message = req.__(messages[code][0]);
|
||||
return next(err);
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
module.exports = class ForbiddenError extends Error {
|
||||
const SalixError = require('./salixError');
|
||||
module.exports = class ForbiddenError extends SalixError {
|
||||
constructor(message, code, ...translateArgs) {
|
||||
super(message);
|
||||
this.name = 'ForbiddenError';
|
||||
this.name = ForbiddenError.name;
|
||||
this.statusCode = 403;
|
||||
this.code = code;
|
||||
this.translateArgs = translateArgs;
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
module.exports = class SalixError extends Error {
|
||||
constructor(message) {
|
||||
super(message);
|
||||
}
|
||||
};
|
|
@ -4,10 +4,11 @@
|
|||
* the final user, so they cannot contain sensitive data and must
|
||||
* be understandable by people who do not have a technical profile.
|
||||
*/
|
||||
module.exports = class UserError extends Error {
|
||||
const SalixError = require('./salixError');
|
||||
module.exports = class UserError extends SalixError {
|
||||
constructor(message, code, ...translateArgs) {
|
||||
super(message);
|
||||
this.name = 'UserError';
|
||||
this.name = UserError.name;
|
||||
this.statusCode = 400;
|
||||
this.code = code;
|
||||
this.translateArgs = translateArgs;
|
||||
|
|
Loading…
Reference in New Issue