'WebFilterChain statusCode always wrong?
I'm trying to add a WebFilter that reads and logs the status code of any response.
Problem: if it comes to a WebExchangeBindException like as follows, that status code is always HTTP 200 OK. But why?
@Component
public class ReactiveLoggingFilter implements WebFilter {
@Override
public Mono<Void> filter(ServerWebExchange exchange, WebFilterChain chain) {
return chain.doOnTerminate(() -> {
System.out.println(exchange.getResponse().getRawStatusCode());
System.out.println(exchange.getResponse().getStatusCode());
});
}
}
@RestController
public class ExampleServlet {
@GetMapping("/example")
public Mono<String> example(@Valid Example exmaple) {
return Mono.just("OK");
}
}
public class Example {
@NotBlank
private String name;
//getter, setter
}
Interesting: when using the @Deprecated method, I get the correct statuscode:
.doAfterSuccessOrError((e, t) -> {
System.out.println(exchange.getResponse().getStatusCode());
})
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
