Register status handler exceptions in observations

Prior to this commit, `RestClientException` thrown by status handlers
would not be registered as observation errors. This commit ensures that
such exceptions are first caught, registered in the observation and
rethrown as expected.

Closes gh-32575
This commit is contained in:
Brian Clozel
2024-04-20 19:44:11 +02:00
parent 0268180799
commit 5aa576f5c6
2 changed files with 26 additions and 7 deletions

View File

@@ -228,13 +228,13 @@ final class DefaultRestClient implements RestClient {
}
throw unknownContentTypeException;
}
catch (UncheckedIOException | IOException | HttpMessageNotReadableException ex) {
catch (UncheckedIOException | IOException | HttpMessageNotReadableException exc) {
Throwable cause;
if (ex instanceof UncheckedIOException uncheckedIOException) {
if (exc instanceof UncheckedIOException uncheckedIOException) {
cause = uncheckedIOException.getCause();
}
else {
cause = ex;
cause = exc;
}
RestClientException restClientException = new RestClientException("Error while extracting response for type [" +
ResolvableType.forType(bodyType) + "] and content type [" + contentType + "]", cause);
@@ -243,6 +243,12 @@ final class DefaultRestClient implements RestClient {
}
throw restClientException;
}
catch (RestClientException restClientException) {
if (observation != null) {
observation.error(restClientException);
}
throw restClientException;
}
finally {
if (observation != null) {
observation.stop();