From ed8d23a2aa2f7e7d41d01bf80d83ef61d8cbdcb4 Mon Sep 17 00:00:00 2001 From: Rafa Herzog <49111482+necronyxon@users.noreply.github.com> Date: Fri, 15 May 2026 18:52:40 -0300 Subject: [PATCH] fix: error updating quotas Retry on `Internal server error` when updating quotas. Refs: #579 --- .../adapter/apis/APIManagerQuotaAdapter.java | 26 ++++++++++++------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/modules/apim-adapter/src/main/java/com/axway/apim/adapter/apis/APIManagerQuotaAdapter.java b/modules/apim-adapter/src/main/java/com/axway/apim/adapter/apis/APIManagerQuotaAdapter.java index ebe53658c..d3bddff2c 100644 --- a/modules/apim-adapter/src/main/java/com/axway/apim/adapter/apis/APIManagerQuotaAdapter.java +++ b/modules/apim-adapter/src/main/java/com/axway/apim/adapter/apis/APIManagerQuotaAdapter.java @@ -151,17 +151,12 @@ public void saveQuota(APIQuota quotaConfig, String quotaId) throws AppException int statusCode = httpResponse.getStatusCode(); String response = httpResponse.getResponseBody(); if (statusCode < 200 || statusCode > 299) { - if ((statusCode == 400) && (response.contains("API not found"))) { - LOG.warn("Got unexpected error: 'API not found' while saving quota configuration ... Try again in {} milliseconds. (you may set -retryDelay )", cmd.getRetryDelay()); + if ((statusCode == 400 && response.contains("API not found")) + || (statusCode == 500 && response.contains("Internal server error")) + ) { + LOG.warn("Got unexpected error while saving quota configuration ... Try again in {} milliseconds. (you may set -retryDelay )", cmd.getRetryDelay()); Thread.sleep(cmd.getRetryDelay()); - httpResponse = httpHelper.execute(request, true); - response = httpResponse.getResponseBody(); - statusCode = httpResponse.getStatusCode(); - if (statusCode < 200 || statusCode > 299) { - throw new AppException("Can't update API-Manager Quota-Configuration. Response: '" + response + "'", ErrorCode.API_MANAGER_COMMUNICATION); - } else { - LOG.info("Successfully created API-Access on retry. Received Status-Code: {}", statusCode); - } + retrySaveQuota(request); } else { throw new AppException("Can't update API-Manager Quota-Configuration. Response: '" + response + "'", ErrorCode.API_MANAGER_COMMUNICATION); } @@ -188,6 +183,17 @@ public APIQuota getDefaultQuota(Quota quotaType) throws AppException { return quotaConfig; } + private static void retrySaveQuota(RestAPICall request) throws IOException { + Response httpResponse = httpHelper.execute(request, true); + String response = httpResponse.getResponseBody(); + int statusCode = httpResponse.getStatusCode(); + if (statusCode < 200 || statusCode > 299) { + throw new AppException("Can't update API-Manager Quota-Configuration. Response: '" + response + "'", ErrorCode.API_MANAGER_COMMUNICATION); + } else { + LOG.info("Successfully created API-Access on retry. Received Status-Code: {}", statusCode); + } + } + private static APIQuota filterQuotaForAPI(APIQuota quotaConfig, API api) throws AppException { List apiRestrictions = new ArrayList<>(); try {