ProblemExceptionHandler implements WebExceptionHandler { @Nonnull @Override public Mono<Void> handle(final ServerWebExchange exchange, final Throwable throwable) { if (throwable instanceof ResponseStatusException) { final Mono<ResponseEntity<Problem>> entityMono = find(exchange, throwable); return entityMono.flatMap(entity -> AdviceUtils.setHttpResponse(entity, exchange, mapper)); } return Mono.error(throwable); } ProblemExceptionHandler(final ObjectMapper mapper, final HttpAdviceTrait advice); @Nonnull @Override Mono<Void> handle(final ServerWebExchange exchange, final Throwable throwable);  }
@Test void shouldHandleResponseStatusException() { MockServerHttpResponse response = exchange.getResponse(); handler.handle(exchange, new ResponseStatusException(HttpStatus.CONFLICT)).block(); assertThat(response.getStatusCode(), is(HttpStatus.CONFLICT)); assertThat(response.getHeaders().getContentType(), is(MediaTypes.PROBLEM)); assertThat(response.getBodyAsString().block(), containsString(Status.CONFLICT.getReasonPhrase())); }
@Test void shouldPropagateOtherExceptions() { try { handler.handle(exchange, new RuntimeException("mock exception")).block(); fail("A RuntimeException should have been thrown"); } catch (RuntimeException e) { assertThat(e.getMessage(), is("mock exception")); } }