1616public class GlobalExceptionHandler {
1717
1818 private static final Logger logger = LoggerFactory .getLogger (GlobalExceptionHandler .class );
19+ private static final String INVALID_PARAMETER = "INVALID_PARAMETER" ;
1920
2021 @ ExceptionHandler (NotFoundException .class )
2122 public ResponseEntity <ErrorResponse > handleNotFoundException (NotFoundException ex ) {
@@ -29,7 +30,7 @@ public ResponseEntity<ErrorResponse> handleNotFoundException(NotFoundException e
2930 @ ExceptionHandler (MethodArgumentTypeMismatchException .class )
3031 public ResponseEntity <ErrorResponse > handleTypeMismatch (MethodArgumentTypeMismatchException ex ) {
3132 ErrorResponse error = new ErrorResponse (
32- " INVALID_PARAMETER" ,
33+ INVALID_PARAMETER ,
3334 String .format ("Invalid value '%s' for parameter '%s'" , ex .getValue (), ex .getName ()),
3435 Map .of ("parameter" , ex .getName (), "providedValue" , String .valueOf (ex .getValue ()))
3536 );
@@ -43,19 +44,19 @@ public ResponseEntity<ErrorResponse> handleValidationException(MethodArgumentNot
4344 String parameterName = fieldError .getField ();
4445 Object rejectedValue = fieldError .getRejectedValue ();
4546 ErrorResponse error = new ErrorResponse (
46- " INVALID_PARAMETER" ,
47+ INVALID_PARAMETER ,
4748 String .format ("Invalid value '%s' for parameter '%s'" , rejectedValue , parameterName ),
4849 Map .of ("parameter" , parameterName , "providedValue" , String .valueOf (rejectedValue ))
4950 );
5051 return ResponseEntity .status (HttpStatus .BAD_REQUEST ).body (error );
5152 }
52- ErrorResponse error = new ErrorResponse (" INVALID_PARAMETER" , "Validation failed" );
53+ ErrorResponse error = new ErrorResponse (INVALID_PARAMETER , "Validation failed" );
5354 return ResponseEntity .status (HttpStatus .BAD_REQUEST ).body (error );
5455 }
5556
5657 @ ExceptionHandler (IllegalArgumentException .class )
5758 public ResponseEntity <ErrorResponse > handleIllegalArgument (IllegalArgumentException ex ) {
58- ErrorResponse error = new ErrorResponse (" INVALID_PARAMETER" , ex .getMessage ());
59+ ErrorResponse error = new ErrorResponse (INVALID_PARAMETER , ex .getMessage ());
5960 return ResponseEntity .status (HttpStatus .BAD_REQUEST ).body (error );
6061 }
6162
0 commit comments