private Long getRetryAfter(Exception candidate) { if (candidate instanceof RestClientResponseException) { String retryAfter = ((RestClientResponseException) candidate).getResponseHeaders().getFirst(RETRY_AFTER); if (retryAfter != null) { return System.currentTimeMillis() + TimeUnit.SECONDS.toMillis(Long.parseLong(retryAfter)); } } return null; }
public static ErrorHttpResponseMessage from(RequestEntity<Object> request, RestClientResponseException e) { StatusCode statusCode = StatusCode.of(e.getRawStatusCode(), e.getStatusText()); Headers headers = new Headers(); e.getResponseHeaders().forEach((k, v) -> headers.put(k, v)); InputStream body = new ByteArrayInputStream(e.getResponseBodyAsByteArray()); return new ErrorHttpResponseMessage(statusCode, headers, body, new ErrorHttpRequestMessage(request)); }