File tree Expand file tree Collapse file tree 1 file changed +17
-2
lines changed Expand file tree Collapse file tree 1 file changed +17
-2
lines changed Original file line number Diff line number Diff line change @@ -9,20 +9,35 @@ export class HttpExceptionFilter implements ExceptionFilter {
99 const request = ctx . getRequest < Request > ( ) ;
1010
1111 let status : number ;
12+ const isUniqueConstaintException = this . isUniqueConstraintException ( exception ) ;
1213 try {
13- status = exception . getStatus ( ) ;
14+ status = isUniqueConstaintException ? HttpStatus . BAD_REQUEST : exception . getStatus ( ) ;
1415 } catch {
1516 status = HttpStatus . INTERNAL_SERVER_ERROR ;
1617 }
18+ const message = isUniqueConstaintException ? this . getCustomMessageForException ( exception ) : exception . message ;
1719
1820 Logger . error ( exception , exception . stack ) ;
1921
2022 response . status ( status ) . json ( {
2123 path : request . url ,
2224 name : exception . name ,
23- message : exception . message ,
25+ message : message ,
2426 exception : exception ,
2527 stack : exception . stack ,
2628 } ) ;
2729 }
30+
31+ isUniqueConstraintException ( exception : HttpException ) : boolean {
32+ return exception . message . includes ( "Unique constraint failed on the fields" ) ;
33+ }
34+
35+ getCustomMessageForException ( exception : HttpException ) : string {
36+ let message = exception . message ;
37+ message = ( message . includes ( "build.update()" ) ) ? "There is already a build with this ci build id."
38+ : ( message . includes ( "project.create()" ) ) ? "Project exists with this name."
39+ : ( message . includes ( "user.create()" ) ) ? "This user already exists." : message ;
40+ return message ;
41+ }
42+
2843}
You can’t perform that action at this time.
0 commit comments