Update error-handling, show underprivileged notification error

This commit is contained in:
Tuan Dang
2023-11-27 15:50:00 +07:00
parent 6579b3c93f
commit 814b71052d
6 changed files with 18 additions and 8 deletions
@@ -551,7 +551,7 @@ export const addMachineToWorkspace = async (req: Request, res: Response) => {
const hasRequiredPrivileges = isAtLeastAsPrivilegedWorkspace(permission, rolePermission);
if (!hasRequiredPrivileges) throw ForbiddenRequestError({
message: "Failed to add a more privileged MI to workspace"
message: "Failed to add a more privileged MI to project"
});
let customRole;
@@ -39,8 +39,9 @@ export const requestErrorHandler: ErrorRequestHandler = async (
Sentry.captureException(error);
delete (<any>error).stacktrace // remove stack trace from being sent to client
res.status((<RequestError>error).statusCode).json(error); // revise json part here
res.status((<RequestError>error).statusCode).send(
await error.format(req)
);
next();
};
+3 -2
View File
@@ -53,9 +53,10 @@ export default class RequestError extends Error {
){
super(message)
this._logLevel = logLevel || LogLevel.INFO
this._logLevel = logLevel || LogLevel.INFO;
this._logName = LogLevel[this._logLevel];
this.statusCode = statusCode
this.statusCode = statusCode;
this.message = message;
this.type = type
this.context = context || {}
this.extra = []