[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:
Gaël L'hopital
2026-02-26 07:04:03 +01:00
committed by GitHub
parent d525f7760a
commit 1b6731f6bd
2 changed files with 8 additions and 2 deletions
@@ -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