diff --git a/loopback/server/middleware/error-handler.js b/loopback/server/middleware/error-handler.js index 725826ae7..66e75c47f 100644 --- a/loopback/server/middleware/error-handler.js +++ b/loopback/server/middleware/error-handler.js @@ -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); } diff --git a/loopback/util/forbiddenError.js b/loopback/util/forbiddenError.js index 998cb4593..261f89f06 100644 --- a/loopback/util/forbiddenError.js +++ b/loopback/util/forbiddenError.js @@ -1,4 +1,6 @@ -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'; diff --git a/loopback/util/salixError.js b/loopback/util/salixError.js new file mode 100644 index 000000000..427b871ab --- /dev/null +++ b/loopback/util/salixError.js @@ -0,0 +1,5 @@ +module.exports = class SalixError extends Error { + constructor(message) { + super(message); + } +}; diff --git a/loopback/util/user-error.js b/loopback/util/user-error.js index c2d01e080..6ba851ba8 100644 --- a/loopback/util/user-error.js +++ b/loopback/util/user-error.js @@ -4,7 +4,9 @@ * 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';