Skip to content

Commit

Permalink
Improve handling of interrupted request by alllowing retries
Browse files Browse the repository at this point in the history
Rebased
Reintroducing TOO_MANY_REQUESTS

Signed-off-by: clinique <gael@lhopital.org>
Signed-off-by: gael@lhopital.org <gael@lhopital.org>
  • Loading branch information
clinique committed Mar 25, 2024
1 parent 9cf91cc commit c06b39b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -350,15 +350,19 @@ public synchronized <T> T executeUri(URI uri, HttpMethod method, Class<T> clazz,
try {
exception = new NetatmoException(deserializer.deserialize(ApiError.class, responseBody));
} catch (NetatmoException e) {
exception = new NetatmoException("Error deserializing error: %s".formatted(statusCode.getMessage()));
if (statusCode == Code.TOO_MANY_REQUESTS) {
exception = new NetatmoException(statusCode.getMessage());
} else {
exception = new NetatmoException(
"Error deserializing error: %s".formatted(statusCode.getMessage()));
}
}
throw exception;
} catch (NetatmoException e) {
if (e.getStatusCode() == ServiceError.MAXIMUM_USAGE_REACHED) {
if (statusCode == Code.TOO_MANY_REQUESTS
|| exception.getStatusCode() == ServiceError.MAXIMUM_USAGE_REACHED) {
prepareReconnection(API_LIMIT_INTERVAL_S,
"@text/maximum-usage-reached [ \"%d\" ]".formatted(API_LIMIT_INTERVAL_S), null, null);
}
throw e;
throw exception;
} catch (InterruptedException | TimeoutException | ExecutionException e) {
if (retryCount > 0) {
logger.debug("Request error, retry counter: {}", retryCount);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
*/
package org.openhab.binding.netatmo.internal.handler.capability;

import static java.time.temporal.ChronoUnit.SECONDS;
import static java.time.temporal.ChronoUnit.*;

import java.time.Duration;
import java.time.Instant;
Expand All @@ -38,6 +38,7 @@
public class RefreshCapability extends Capability {
private static final Duration DEFAULT_DELAY = Duration.of(20, SECONDS);
private static final Duration PROBING_INTERVAL = Duration.of(120, SECONDS);
private static final Duration OFFLINE_INTERVAL = Duration.of(15, MINUTES);

private final Logger logger = LoggerFactory.getLogger(RefreshCapability.class);

Expand Down

0 comments on commit c06b39b

Please sign in to comment.