Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions src/http-exception.filter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);

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

Expand Down