Files
spring-boot-rest/spring-mvc-basics-3/src/main/java/com/baeldung/spring/exceptions/GlobalControllerExceptionHandler.java
2019-12-16 22:25:22 +02:00

17 lines
717 B
Java

package com.baeldung.spring.exceptions;
import org.springframework.core.convert.ConversionFailedException;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
@ControllerAdvice
public class GlobalControllerExceptionHandler {
@ExceptionHandler(ConversionFailedException.class)
public ResponseEntity<String> handleConflict(RuntimeException ex) {
// Remove the try-catch block in the StringToEnumConverter if we want to handle the exception here
return new ResponseEntity<>(ex.getMessage(), HttpStatus.BAD_REQUEST);
}
}