when native query fails to execute which method of restcontrolleradvice class would be executed between sqlgrammar exception and Exception
@RestControllerAdvice public class ExceptionControllerAdvice {
@Autowired
Helper HelperUtilities;
@Autowired
HttpServletRequest request;
@Autowired
Telemetry tel;
@ExceptionHandler(SQLGrammarException.class)
public ResponseEntity<ErrorResponse> exceptionHandler(SQLGrammarException ex) {
ex.printStackTrace();
ErrorResponse error = new ErrorResponse();
error.setErrorCode(500);
error.setMessage(ex.getMessage());
// Log this error in Kibana using stdout
String CurrentUser = HelperUtilities.getCurrentUserNameFromJWT();
String ErrorDetails = "Server Side Error (UnHandled):: User - " + CurrentUser
+ " ::: Method - exceptionHandler(Exception ex) :: Error Details - "
+ HelperUtilities.getStackTraceAsString(ex);
return new ResponseEntity<ErrorResponse>(error, HttpStatus.INTERNAL_SERVER_ERROR);
}
@ExceptionHandler(Exception.class)
public ResponseEntity<ErrorResponse> exceptionHandler(Exception ex) {
ex.printStackTrace();
ErrorResponse error = new ErrorResponse();
error.setErrorCode(400);
error.setMessage(ex.getLocalizedMessage());
String CurrentUser = HelperUtilities.getCurrentUserNameFromJWT();
String ErrorDetails = "Server Side Error (UnHandled):: User - " + CurrentUser
+ " ::: Method - exceptionHandler(Exception ex) :: Error Details - "
+ HelperUtilities.getStackTraceAsString(ex);
tel.setExeceptionEventData( HttpStatus.BAD_REQUEST.toString(),ErrorDetails, new Object() {
}.getClass().getEnclosingMethod().getName());
return new ResponseEntity<ErrorResponse>(error, HttpStatus.INTERNAL_SERVER_ERROR);
}