Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public ResponseEntity<Object> getResponse(URI uri, HttpHeaders httpHeaders,
- Object obj) {
- ResponseEntity<Object> response = null;
- try {
- response = restTemplate.exchange(uri, HttpMethod.POST, new HttpEntity<>(obj, httpHeaders),
- Object.class);
- } catch (Exception serverEx) {
- LOGGER.error("ERROR while calling API.Full Exception: ",serverEx);
- response.getBody().setLink(object.getUrl());
- }
- return response;
- }
- public class RestTemplateResponseErrorHandler implements ResponseErrorHandler {
- private static final Logger LOGGER = LogManager.getLogger(RestTemplateResponseErrorHandler.class);
- @Override
- public boolean hasError(ClientHttpResponse httpResponse) throws IOException {
- return (httpResponse.getStatusCode().series() == Series.CLIENT_ERROR
- || httpResponse.getStatusCode().series() == Series.SERVER_ERROR);
- }
- @Override
- public void handleError(ClientHttpResponse httpResponse) {
- //Log The Error but contibue the flow
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement