refs #6172 perf: translate message error
gitea/salix/pipeline/head This commit looks good Details

This commit is contained in:
Javier Segarra 2024-01-02 11:59:35 +01:00
parent 7fd27cd7a5
commit 33da9c7fec
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';