Currently Spring Boot will return INTERNAL_SERVER_ERROR if OptimisticLockingFailureException thrown, It's better to use CONFLICT instead, to archive that I need customize an ExceptionHandler
@ControllerAdvice
@RequiredArgsConstructor
public class GlobalExceptionHandler {
@ExceptionHandler(OptimisticLockingFailureException.class)
public void handleConflict(HttpServletRequest request, HttpServletResponse response, Exception e)
throws IOException {
response.sendError(HttpStatus.CONFLICT.value());
}
}
It would be great if Spring Boot handle it by default, or provide a way to map in properties, for example:
server.error.mapping:
"org.springframework.dao.OptimisticLockingFailureException": 409
Currently Spring Boot will return
INTERNAL_SERVER_ERRORif OptimisticLockingFailureException thrown, It's better to useCONFLICTinstead, to archive that I need customize an ExceptionHandlerIt would be great if Spring Boot handle it by default, or provide a way to map in properties, for example: