Skip to content

Commit e3ac6fb

Browse files
authored
Add clearer error message for unauthorized user (#159)
* Add clearer error message for unauthorized user Fixes part of the issue: Visual-Regression-Tracker/Visual-Regression-Tracker#296 * Renamed the method to a more relevant one.
1 parent 7e42852 commit e3ac6fb

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/http-exception.filter.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,13 @@ export class HttpExceptionFilter implements ExceptionFilter {
1010

1111
let status: number;
1212
const isUniqueConstaintException = this.isUniqueConstraintException(exception);
13+
const isForbiddenException = this.isForbiddenException(exception);
1314
try {
1415
status = isUniqueConstaintException ? HttpStatus.BAD_REQUEST : exception.getStatus();
1516
} catch {
1617
status = HttpStatus.INTERNAL_SERVER_ERROR;
1718
}
18-
const message = isUniqueConstaintException ? this.getCustomMessageForException(exception) : exception.message;
19+
const message = (isUniqueConstaintException || isForbiddenException) ? this.getCustomMessageForException(exception) : exception.message;
1920

2021
Logger.error(exception, exception.stack);
2122

@@ -28,6 +29,10 @@ export class HttpExceptionFilter implements ExceptionFilter {
2829
});
2930
}
3031

32+
isForbiddenException(exception: HttpException): boolean {
33+
return exception.message.includes("Forbidden resource");
34+
}
35+
3136
isUniqueConstraintException(exception: HttpException): boolean {
3237
return exception.message.includes("Unique constraint failed on the fields");
3338
}
@@ -36,7 +41,8 @@ export class HttpExceptionFilter implements ExceptionFilter {
3641
let message = exception.message;
3742
message = (message.includes("build.update()")) ? "There is already a build with this ci build id."
3843
: (message.includes("project.create()")) ? "Project exists with this name."
39-
: (message.includes("user.create()")) ? "This user already exists." : message;
44+
: (message.includes("user.create()")) ? "This user already exists."
45+
: (message.includes("Forbidden resource")) ? "You do not have permission to perform this operation." : message;
4046
return message;
4147
}
4248

0 commit comments

Comments
 (0)