Skip to content

Commit

Permalink
[hue] API v1: retry once on timeout for GET requests to the bridge (o…
Browse files Browse the repository at this point in the history
…penhab#16902)

Fix openhab#16723

Signed-off-by: Laurent Garnier <lg.hc@free.fr>
  • Loading branch information
lolodomo committed Jun 22, 2024
1 parent 4f64bb9 commit d2466d5
Showing 1 changed file with 13 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1096,6 +1096,11 @@ private HueResult doNetwork(String address, HttpMethod requestMethod)

private HueResult doNetwork(String address, HttpMethod requestMethod, @Nullable String body)
throws ConfigurationException, CommunicationException {
return doNetwork(address, requestMethod, body, requestMethod == HttpMethod.GET);
}

private HueResult doNetwork(String address, HttpMethod requestMethod, @Nullable String body, boolean retryOnTimeout)
throws ConfigurationException, CommunicationException {
logger.trace("Hue request: {} - URL = '{}'", requestMethod, address);
try {
final Request request = httpClient.newRequest(address).method(requestMethod).timeout(timeout,
Expand Down Expand Up @@ -1123,9 +1128,14 @@ private HueResult doNetwork(String address, HttpMethod requestMethod, @Nullable
e.getCause());
}
} catch (TimeoutException e) {
String message = e.getMessage();
logger.debug("TimeoutException occurred during execution: {}", message, e);
throw new CommunicationException(message == null ? TEXT_OFFLINE_COMMUNICATION_ERROR : message);
if (retryOnTimeout) {
logger.debug("TimeoutException occurred during execution, retry");
return doNetwork(address, requestMethod, body, false);
} else {
String message = e.getMessage();
logger.debug("TimeoutException occurred during execution: {}", message, e);
throw new CommunicationException(message == null ? TEXT_OFFLINE_COMMUNICATION_ERROR : message);
}
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
String message = e.getMessage();
Expand Down

0 comments on commit d2466d5

Please sign in to comment.