spring-boot-mysql-rest-api-tutorial
spring-boot-mysql-rest-api-tutorial copied to clipboard
Feature : Added the 'ExceptionHand' class for exception handling
Added a new class 'ExceptionHand' in the 'Exception' file in the master branch to avoid the complexity of displaying errors when retrieving or deleting data that does not exist in the database by showing a clear and simple message. code : package com.example.easynotes.exception; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.ControllerAdvice; import org.springframework.web.bind.annotation.ExceptionHandler;
@ControllerAdvice public class ExceptionHand {
@ExceptionHandler(ResourceNotFoundException.class)
public ResponseEntity<String> handleMyCustomException(ResourceNotFoundException ex) {
// Handle the exception and return an appropriate response
return new ResponseEntity<>( ex.getMessage(), HttpStatus.NOT_FOUND);
}
}
Error message before the addition of the class:
L'erreur qui s'affiche après l'ajout de la class ExceptionHand