spring-boot-mysql-rest-api-tutorial icon indicating copy to clipboard operation
spring-boot-mysql-rest-api-tutorial copied to clipboard

Feature : Added the 'ExceptionHand' class for exception handling

Open jguirimm opened this issue 2 years ago • 0 comments

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: Erreur Exception L'erreur qui s'affiche après l'ajout de la class ExceptionHand Exception_solu l'arborecsence

jguirimm avatar Jan 12 '24 23:01 jguirimm