1 package de.juplo.kafka.chatroom.api;
3 import de.juplo.kafka.chatroom.domain.MessageMutationException;
4 import org.springframework.http.HttpStatus;
5 import org.springframework.http.ProblemDetail;
6 import org.springframework.http.ResponseEntity;
7 import org.springframework.web.bind.annotation.ControllerAdvice;
8 import org.springframework.web.bind.annotation.ExceptionHandler;
9 import org.springframework.web.reactive.result.method.annotation.ResponseEntityExceptionHandler;
10 import org.springframework.web.server.ServerWebExchange;
11 import reactor.core.publisher.Mono;
15 public class ChatroomControllerAdvice extends ResponseEntityExceptionHandler
17 @ExceptionHandler(MessageMutationException.class)
18 public final Mono<ResponseEntity<Object>> handleException(MessageMutationException e, ServerWebExchange exchange)
20 final HttpStatus status = HttpStatus.BAD_REQUEST;
21 ProblemDetail body = ProblemDetail.forStatusAndDetail(status, e.getMessage());
22 body.setProperty("new", e.getToAdd());
23 body.setProperty("existing", e.getExisting());
24 return handleExceptionInternal(e, body, null, status, exchange);