Skip to content

Commit 39d5e00

Browse files
Trying to retrieve status code in case IAE is thrown; fixes gh-1382
1 parent d465fb2 commit 39d5e00

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

spring-cloud-sleuth-core/src/main/java/org/springframework/cloud/sleuth/instrument/web/client/TraceWebClientBeanPostProcessor.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
import org.springframework.beans.factory.config.BeanPostProcessor;
4343
import org.springframework.cloud.sleuth.instrument.reactor.ReactorSleuth;
4444
import org.springframework.core.io.buffer.DataBuffer;
45+
import org.springframework.http.HttpStatus;
4546
import org.springframework.web.client.RestClientException;
4647
import org.springframework.web.reactive.function.client.ClientRequest;
4748
import org.springframework.web.reactive.function.client.ClientResponse;
@@ -349,7 +350,7 @@ void terminateSpanOnCancel() {
349350

350351
void terminateSpan(@Nullable ClientResponse clientResponse,
351352
@Nullable Throwable throwable) {
352-
if (clientResponse == null || clientResponse.statusCode() == null) {
353+
if (clientResponse == null || tryStatusCode(clientResponse) == null) {
353354
if (log.isDebugEnabled()) {
354355
log.debug("No response was returned. Will close the span ["
355356
+ this.span + "]");
@@ -373,6 +374,15 @@ void terminateSpan(@Nullable ClientResponse clientResponse,
373374
handleReceive(this.span, this.ws, clientResponse, throwable);
374375
}
375376

377+
private HttpStatus tryStatusCode(ClientResponse clientResponse) {
378+
try {
379+
return clientResponse.statusCode();
380+
}
381+
catch (Exception ex) {
382+
return null;
383+
}
384+
}
385+
376386
}
377387

378388
}

0 commit comments

Comments
 (0)