@@ -51,22 +51,25 @@ public <REQUEST, RESPONSE> ClientHttpResponse<RESPONSE> syncHttpResponse(ClientH
51
51
} catch (final WebClientResponseException ex ) {
52
52
final String errorMessage = String .format ("Error in making rest call. Error=%s Headers=%s statusCode=%s" ,
53
53
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 );
55
56
} catch (final HttpStatusCodeException ex ) {
56
57
final String errorMessage = String .format ("Error in making rest call. Error=%s Headers=%s statusCode=%s" ,
57
58
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 );
59
61
} catch (final UnknownContentTypeException ex ) {
60
62
// It was observed that this exception was thrown whenever there was a HTTP 5XX error
61
63
// returned in the REST call. The handle went into `RestClientException` which is the parent
62
64
// class of `UnknownContentTypeException` and hence some contextual information was lost
63
65
final String errorMessage = String .format ("Error in making rest call. Error=%s Headers=%s" ,
64
66
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 );
66
69
} catch (final Exception ex ) {
67
70
final String errorMessage = String
68
71
.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 );
70
73
}
71
74
}
72
75
@@ -131,11 +134,12 @@ private <RESPONSE> ClientHttpResponse<RESPONSE> generateResponse(ResponseEntity<
131
134
private <REQUEST , RESPONSE > ClientHttpResponse <RESPONSE > handleException (
132
135
final Exception exception ,
133
136
final String errorMessage ,
137
+ final String responseBody ,
134
138
final HttpStatus httpStatus ,
135
139
final ClientHttpRequest <REQUEST , RESPONSE > httpRequest ) {
136
140
log .error ("Exception while executing http request for requestUrl={}, status={}, errorMessage={}" , httpRequest .getUrl (), httpStatus , errorMessage );
137
141
httpRequest .getRetryHandlers ()
138
142
.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 ();
140
144
}
141
145
}
0 commit comments