org.springframework.web.client.RestClientResponseException Java Examples
The following examples show how to use
org.springframework.web.client.RestClientResponseException.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: VaultSysTemplate.java From spring-vault with Apache License 2.0 | 6 votes |
@Override public VaultHealth doWithRestOperations(RestOperations restOperations) { try { ResponseEntity<VaultHealthImpl> healthResponse = restOperations.exchange("sys/health", HttpMethod.GET, emptyNamespace(null), VaultHealthImpl.class); return healthResponse.getBody(); } catch (RestClientResponseException responseError) { try { ObjectMapper mapper = new ObjectMapper(); return mapper.readValue(responseError.getResponseBodyAsString(), VaultHealthImpl.class); } catch (Exception jsonError) { throw responseError; } } }
Example #2
Source File: RestClientResponseExceptionTest.java From hellokoding-courses with MIT License | 5 votes |
<T> ResponseEntity consumeWebService(String url, Class<T> responseType) { try { return restTemplate.getForEntity(url, responseType); } catch (RestClientResponseException e) { return ResponseEntity .status(e.getRawStatusCode()) .body(e.getResponseBodyAsString()); } }
Example #3
Source File: VaultLoginException.java From spring-vault with Apache License 2.0 | 5 votes |
/** * Create a {@link VaultLoginException} given {@code authMethod} and a * {@link Throwable cause}. * @param authMethod must not be {@literal null}. * @param cause must not be {@literal null}. * @return the {@link VaultLoginException}. */ public static VaultLoginException create(String authMethod, Throwable cause) { if (cause instanceof RestClientResponseException) { String response = ((RestClientResponseException) cause).getResponseBodyAsString(); return new VaultLoginException( String.format("Cannot login using %s: %s", authMethod, VaultResponses.getError(response)), cause); } return new VaultLoginException(String.format("Cannot login using %s", cause)); }
Example #4
Source File: UserController.java From springboot-learning-experience with Apache License 2.0 | 4 votes |
@ExceptionHandler(RestClientResponseException.class) public ErrorBody exceptionHandler(HttpClientErrorException e) throws IOException { return new ObjectMapper().readValue(e.getResponseBodyAsString(), ErrorBody.class); }