Assuming 500 status code when an exception was thrown in the controller; fixes gh-1880

This commit is contained in:
Marcin Grzejszczak
2021-03-30 14:06:48 +02:00
parent dad3d80408
commit bd47e12614
2 changed files with 26 additions and 3 deletions

View File

@@ -38,6 +38,7 @@ import reactor.util.context.Context;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.core.Ordered;
import org.springframework.http.HttpStatus;
import org.springframework.http.server.reactive.ServerHttpRequest;
import org.springframework.http.server.reactive.ServerHttpResponse;
import org.springframework.web.method.HandlerMethod;
@@ -422,9 +423,11 @@ public final class TraceWebFilter implements WebFilter, Ordered {
@Override
public int statusCode() {
if (this.throwable != null
&& this.throwable instanceof ResponseStatusException) {
return ((ResponseStatusException) this.throwable).getStatus().value();
if (!this.delegate.isCommitted() && this.throwable != null) {
if (this.throwable instanceof ResponseStatusException) {
return ((ResponseStatusException) this.throwable).getStatus().value();
}
return HttpStatus.INTERNAL_SERVER_ERROR.value();
}
return delegate.getStatusCode() != null ? delegate.getStatusCode().value()
: 0;