From d54e0c71a829dfefc17e48f09ed9307ff31cc560 Mon Sep 17 00:00:00 2001 From: Tim Chamberlain Date: Mon, 14 Nov 2022 10:47:02 -0600 Subject: [PATCH] SPRINT-15: moved response validation into its own method which can be overriden in subclasses --- .../module/api/actions/BaseAPIActionUtil.java | 39 +++++++++---------- 1 file changed, 18 insertions(+), 21 deletions(-) diff --git a/qqq-backend-module-api/src/main/java/com/kingsrook/qqq/backend/module/api/actions/BaseAPIActionUtil.java b/qqq-backend-module-api/src/main/java/com/kingsrook/qqq/backend/module/api/actions/BaseAPIActionUtil.java index f63956db..2c8e0144 100644 --- a/qqq-backend-module-api/src/main/java/com/kingsrook/qqq/backend/module/api/actions/BaseAPIActionUtil.java +++ b/qqq-backend-module-api/src/main/java/com/kingsrook/qqq/backend/module/api/actions/BaseAPIActionUtil.java @@ -304,25 +304,8 @@ public class BaseAPIActionUtil HttpPost request = new HttpPost(url); request.setEntity(recordsToEntity(table, recordList)); - QHttpResponse response = makeRequest(table, request); - int statusCode = response.getStatusCode(); - String responseString = response.getContent(); - if(statusCode != HttpStatus.SC_MULTI_STATUS && statusCode != HttpStatus.SC_OK) - { - String errorMessage = "Did not receive response status code of 200 or 207: " + responseString; - LOG.warn(errorMessage); - throw (new QException(errorMessage)); - } - if(statusCode == HttpStatus.SC_MULTI_STATUS) - { - JSONObject responseJSON = new JSONObject(responseString).getJSONObject("response"); - if(!responseJSON.optString("status").contains("200 OK")) - { - String errorMessage = "Did not receive ok status response: " + responseJSON.optString("description"); - LOG.warn(errorMessage); - throw (new QException(errorMessage)); - } - } + QHttpResponse response = makeRequest(table, request); + validateResponse(response); } catch(QException e) { @@ -349,13 +332,26 @@ public class BaseAPIActionUtil } catch(Exception e) { - LOG.warn("Error in API Insert for [" + table.getName() + "]", e); + LOG.warn("Error in API Update for [" + table.getName() + "]", e); throw new QException("Error executing update: " + e.getMessage(), e); } } + /******************************************************************************* + ** + *******************************************************************************/ + public void validateResponse(QHttpResponse response) throws QException + { + //////////////////////// + // noop at base level // + //////////////////////// + return; + } + + + /******************************************************************************* ** *******************************************************************************/ @@ -469,7 +465,7 @@ public class BaseAPIActionUtil /******************************************************************************* ** *******************************************************************************/ - private void handleResponseError(QTableMetaData table, HttpRequestBase request, QHttpResponse response) throws QException + protected void handleResponseError(QTableMetaData table, HttpRequestBase request, QHttpResponse response) throws QException { int statusCode = response.getStatusCode(); String resultString = response.getContent(); @@ -734,6 +730,7 @@ public class BaseAPIActionUtil { int sleepMillis = getInitialRateLimitBackoffMillis(); int rateLimitsCaught = 0; + while(true) { //////////////////////////////////////////////////////