@@ -51,22 +51,25 @@ public <REQUEST, RESPONSE> ClientHttpResponse<RESPONSE> syncHttpResponse(ClientH
5151 } catch (final WebClientResponseException ex ) {
5252 final String errorMessage = String .format ("Error in making rest call. Error=%s Headers=%s statusCode=%s" ,
5353 ex .getResponseBodyAsString (), ex .getHeaders (), ex .getStatusCode ());
54- return handleException (ex , errorMessage , HttpStatus .valueOf (ex .getStatusCode ().value ()), httpRequest );
54+ return handleException (ex , errorMessage , ex .getResponseBodyAsString (),
55+ HttpStatus .valueOf (ex .getStatusCode ().value ()), httpRequest );
5556 } catch (final HttpStatusCodeException ex ) {
5657 final String errorMessage = String .format ("Error in making rest call. Error=%s Headers=%s statusCode=%s" ,
5758 ex .getResponseBodyAsString (), ex .getResponseHeaders (), ex .getStatusCode ());
58- return handleException (ex , errorMessage , HttpStatus .valueOf (ex .getStatusCode ().value ()), httpRequest );
59+ return handleException (ex , errorMessage , ex .getResponseBodyAsString (),
60+ HttpStatus .valueOf (ex .getStatusCode ().value ()), httpRequest );
5961 } catch (final UnknownContentTypeException ex ) {
6062 // It was observed that this exception was thrown whenever there was a HTTP 5XX error
6163 // returned in the REST call. The handle went into `RestClientException` which is the parent
6264 // class of `UnknownContentTypeException` and hence some contextual information was lost
6365 final String errorMessage = String .format ("Error in making rest call. Error=%s Headers=%s" ,
6466 ex .getResponseBodyAsString (), ex .getResponseHeaders ());
65- return handleException (ex , errorMessage , HttpStatus .valueOf (ex .getRawStatusCode ()), httpRequest );
67+ return handleException (ex , errorMessage , ex .getResponseBodyAsString (),
68+ HttpStatus .valueOf (ex .getRawStatusCode ()), httpRequest );
6669 } catch (final Exception ex ) {
6770 final String errorMessage = String
6871 .format ("Error in making rest call. Error=%s" , ex .getMessage ());
69- return handleException (ex , errorMessage , HttpStatus .INTERNAL_SERVER_ERROR , httpRequest );
72+ return handleException (ex , errorMessage , null , HttpStatus .INTERNAL_SERVER_ERROR , httpRequest );
7073 }
7174 }
7275
@@ -131,11 +134,12 @@ private <RESPONSE> ClientHttpResponse<RESPONSE> generateResponse(ResponseEntity<
131134 private <REQUEST , RESPONSE > ClientHttpResponse <RESPONSE > handleException (
132135 final Exception exception ,
133136 final String errorMessage ,
137+ final String responseBody ,
134138 final HttpStatus httpStatus ,
135139 final ClientHttpRequest <REQUEST , RESPONSE > httpRequest ) {
136140 log .error ("Exception while executing http request for requestUrl={}, status={}, errorMessage={}" , httpRequest .getUrl (), httpStatus , errorMessage );
137141 httpRequest .getRetryHandlers ()
138142 .forEach (handlerId -> RetryHandlerFactory .getHandler (handlerId .toString ()).checkAndThrowRetriableException (exception ));
139- return ClientHttpResponse .<RESPONSE >builder ().error (errorMessage ).status (httpStatus ).build ();
143+ return ClientHttpResponse .<RESPONSE >builder ().error (responseBody ).status (httpStatus ).build ();
140144 }
141145}
0 commit comments