mirror of
https://github.com/danieldemus/openhab-addons
synced 2026-07-29 12:34:21 +02:00
[ecowatt] Handle Http error 500 more gracefully. (#20282)
* Handle Http error 500 more gracefully. Signed-off-by: gael@lhopital.org <gael@lhopital.org>
This commit is contained in:
+6
-2
@@ -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);
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user