diff --git a/src/http-exception.filter.ts b/src/http-exception.filter.ts index dc9f953d..ca3fb3c6 100644 --- a/src/http-exception.filter.ts +++ b/src/http-exception.filter.ts @@ -10,12 +10,13 @@ export class HttpExceptionFilter implements ExceptionFilter { let status: number; const isUniqueConstaintException = this.isUniqueConstraintException(exception); + const isForbiddenException = this.isForbiddenException(exception); try { status = isUniqueConstaintException ? HttpStatus.BAD_REQUEST : exception.getStatus(); } catch { status = HttpStatus.INTERNAL_SERVER_ERROR; } - const message = isUniqueConstaintException ? this.getCustomMessageForException(exception) : exception.message; + const message = (isUniqueConstaintException || isForbiddenException) ? this.getCustomMessageForException(exception) : exception.message; Logger.error(exception, exception.stack); @@ -28,6 +29,10 @@ export class HttpExceptionFilter implements ExceptionFilter { }); } + isForbiddenException(exception: HttpException): boolean { + return exception.message.includes("Forbidden resource"); + } + isUniqueConstraintException(exception: HttpException): boolean { return exception.message.includes("Unique constraint failed on the fields"); } @@ -36,7 +41,8 @@ export class HttpExceptionFilter implements ExceptionFilter { let message = exception.message; message = (message.includes("build.update()")) ? "There is already a build with this ci build id." : (message.includes("project.create()")) ? "Project exists with this name." - : (message.includes("user.create()")) ? "This user already exists." : message; + : (message.includes("user.create()")) ? "This user already exists." + : (message.includes("Forbidden resource")) ? "You do not have permission to perform this operation." : message; return message; }