diff --git a/bundles/org.openhab.binding.ecowatt/src/main/java/org/openhab/binding/ecowatt/internal/restapi/EcowattRestApi.java b/bundles/org.openhab.binding.ecowatt/src/main/java/org/openhab/binding/ecowatt/internal/restapi/EcowattRestApi.java index c70eedbba1..6998a5dc36 100644 --- a/bundles/org.openhab.binding.ecowatt/src/main/java/org/openhab/binding/ecowatt/internal/restapi/EcowattRestApi.java +++ b/bundles/org.openhab.binding.ecowatt/src/main/java/org/openhab/binding/ecowatt/internal/restapi/EcowattRestApi.java @@ -104,15 +104,19 @@ public class EcowattRestApi { if (response.getHeaders().contains(HttpHeader.RETRY_AFTER)) { try { retryAfter = Integer.parseInt(response.getHeaders().get(HttpHeader.RETRY_AFTER)); + throw new EcowattApiLimitException(retryAfter, "@text/exception.api-limit-reached-params", + retryAfter); } catch (NumberFormatException e) { + throw new EcowattApiLimitException(retryAfter, "@text/exception.api-limit-reached"); } } - throw new EcowattApiLimitException(retryAfter, "@text/exception.api-limit-reached"); + } else if (statusCode == HttpStatus.INTERNAL_SERVER_ERROR_500) { + int retryAfter = 60; + throw new EcowattApiLimitException(retryAfter, "@text/exception.server-error", retryAfter); } else if (statusCode != HttpStatus.OK_200) { throw new CommunicationException("@text/exception.api-request-failed-params", statusCode, response.getContentAsString()); } - try { EcowattApiResponse deserializedResp = gson.fromJson(response.getContentAsString(), EcowattApiResponse.class); diff --git a/bundles/org.openhab.binding.ecowatt/src/main/resources/OH-INF/i18n/ecowatt.properties b/bundles/org.openhab.binding.ecowatt/src/main/resources/OH-INF/i18n/ecowatt.properties index 66d13e9e3b..1d9e6f07a9 100644 --- a/bundles/org.openhab.binding.ecowatt/src/main/resources/OH-INF/i18n/ecowatt.properties +++ b/bundles/org.openhab.binding.ecowatt/src/main/resources/OH-INF/i18n/ecowatt.properties @@ -49,4 +49,6 @@ exception.api-request-failed = REST API request failed exception.api-request-failed-params = REST API request failed: statusCode={0}, message={1} exception.empty-api-response = API response is empty exception.parsing-api-response-failed = Parsing of the API response failed +exception.api-limit-reached-params = API limit reached; will retry in {0} seconds exception.api-limit-reached = API limit reached; will retry later +exception.server-error = Server error, new attempt in {0} seconds