mirror of
https://github.com/Kingsrook/qqq.git
synced 2025-07-18 05:01:07 +00:00
SPRINT-15: moved response validation into its own method which can be overriden in subclasses
This commit is contained in:
@ -304,25 +304,8 @@ public class BaseAPIActionUtil
|
|||||||
HttpPost request = new HttpPost(url);
|
HttpPost request = new HttpPost(url);
|
||||||
request.setEntity(recordsToEntity(table, recordList));
|
request.setEntity(recordsToEntity(table, recordList));
|
||||||
|
|
||||||
QHttpResponse response = makeRequest(table, request);
|
QHttpResponse response = makeRequest(table, request);
|
||||||
int statusCode = response.getStatusCode();
|
validateResponse(response);
|
||||||
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));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
catch(QException e)
|
catch(QException e)
|
||||||
{
|
{
|
||||||
@ -349,13 +332,26 @@ public class BaseAPIActionUtil
|
|||||||
}
|
}
|
||||||
catch(Exception e)
|
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);
|
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();
|
int statusCode = response.getStatusCode();
|
||||||
String resultString = response.getContent();
|
String resultString = response.getContent();
|
||||||
@ -734,6 +730,7 @@ public class BaseAPIActionUtil
|
|||||||
{
|
{
|
||||||
int sleepMillis = getInitialRateLimitBackoffMillis();
|
int sleepMillis = getInitialRateLimitBackoffMillis();
|
||||||
int rateLimitsCaught = 0;
|
int rateLimitsCaught = 0;
|
||||||
|
|
||||||
while(true)
|
while(true)
|
||||||
{
|
{
|
||||||
//////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////
|
||||||
|
Reference in New Issue
Block a user