If unhandled error is thrown, there is probability that the error could cause chaos, like blank page or force close.
Fix the error happened with exception handling.
Any unexpected error happened is handled and not causing chaos.
@ExceptionHandler(Exception.class)
public ResponseEntity<Object> handleGlobalException(Exception ex, WebRequest request) {
// Extract the exception message
String errorMessage = ex.getMessage();
// Return a simplified JSON response with the error message
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR)
.body("{\"error\": \"" + errorMessage + "\"}");
}
