Compare commits

...

1 Commits

Author SHA1 Message Date
Javier Segarra 33da9c7fec refs #6172 perf: translate message error
gitea/salix/pipeline/head This commit looks good Details
2024-01-02 11:59:35 +01:00
4 changed files with 13 additions and 3 deletions

View File

@ -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);
}

View File

@ -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';

View File

@ -0,0 +1,5 @@
module.exports = class SalixError extends Error {
constructor(message) {
super(message);
}
};

View File

@ -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';