Advertisement
Guest User

Untitled

a guest
Mar 20th, 2019
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1. public ResponseEntity<Object> getResponse(URI uri, HttpHeaders httpHeaders,
  2. Object obj) {
  3.  
  4. ResponseEntity<Object> response = null;
  5. try {
  6. response = restTemplate.exchange(uri, HttpMethod.POST, new HttpEntity<>(obj, httpHeaders),
  7. Object.class);
  8.  
  9. } catch (Exception serverEx) {
  10. LOGGER.error("ERROR while calling API.Full Exception: ",serverEx);
  11. response.getBody().setLink(object.getUrl());
  12. }
  13.  
  14. return response;
  15. }
  16.  
  17. public class RestTemplateResponseErrorHandler implements ResponseErrorHandler {
  18.  
  19. private static final Logger LOGGER = LogManager.getLogger(RestTemplateResponseErrorHandler.class);
  20.  
  21. @Override
  22. public boolean hasError(ClientHttpResponse httpResponse) throws IOException {
  23. return (httpResponse.getStatusCode().series() == Series.CLIENT_ERROR
  24. || httpResponse.getStatusCode().series() == Series.SERVER_ERROR);
  25. }
  26.  
  27. @Override
  28. public void handleError(ClientHttpResponse httpResponse) {
  29. //Log The Error but contibue the flow
  30. }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement