binance-connector-java
binance-connector-java copied to clipboard
How to get "RetryAfter" header from Response when exception thrown with 429
After reading the following source code, I found that in the response, I could not get the "RetryAfter" response header. This information is quite important. Can you add it?
When the "handleErrorResponse" exception is thrown, I hope to bring this information. Of course, if there are other better ways, that's fine too.
`
public static String handleResponse(Request request, boolean showLimitUsage, ProxyAuth proxy) {
client = HttpClientSingleton.getHttpClient(proxy);
try (Response response = client.newCall(request).execute()) {
if (null == response) {
throw new BinanceServerException("[ResponseHandler] No response from server");
}
String responseAsString = getResponseBodyAsString(response.body());
if (response.code() >= HTTP_STATUS_CODE_400 && response.code() <= HTTP_STATUS_CODE_499) {
throw handleErrorResponse(responseAsString, response.code());
} else if (response.code() >= HTTP_STATUS_CODE_500) {
throw new BinanceServerException(responseAsString, response.code());
}
if (showLimitUsage) {
return getLimitUsage(response, responseAsString);
} else {
return responseAsString;
}
} catch (IOException | IllegalStateException e) {
String exceptionMsg = "OKHTTP Error: ";
if (proxy != null) {
if ((e.getClass().equals(ConnectException.class))) {
exceptionMsg = "Proxy Connection Error: ";
} else if ((e.getClass().equals(UnknownHostException.class))) {
exceptionMsg = "Proxy Unknown Host Error: ";
}
}
throw new BinanceConnectorException("[ResponseHandler] " + exceptionMsg + e.getMessage());
}
}