mirror of
https://github.com/Kingsrook/qqq.git
synced 2025-07-18 13:10:44 +00:00
added retryable exception and method that can be overridden in base classes to allow retrying in different circumstances, added SC_GATEWAY_TIMEOUT as a logger.info
This commit is contained in:
@ -514,7 +514,7 @@ public class BaseAPIActionUtil
|
|||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
else if(statusCode == HttpStatus.SC_BAD_GATEWAY)
|
else if(statusCode == HttpStatus.SC_BAD_GATEWAY || statusCode == HttpStatus.SC_GATEWAY_TIMEOUT)
|
||||||
{
|
{
|
||||||
LOG.info("HTTP " + request.getMethod() + " failed", logPair("table", table.getName()), logPair("statusCode", statusCode), logPair("responseContent", StringUtils.safeTruncate(resultString, 1024, "...")));
|
LOG.info("HTTP " + request.getMethod() + " failed", logPair("table", table.getName()), logPair("statusCode", statusCode), logPair("responseContent", StringUtils.safeTruncate(resultString, 1024, "...")));
|
||||||
didLog = true;
|
didLog = true;
|
||||||
@ -918,7 +918,7 @@ public class BaseAPIActionUtil
|
|||||||
}
|
}
|
||||||
else if(shouldBeRetryableServerErrorException(qResponse))
|
else if(shouldBeRetryableServerErrorException(qResponse))
|
||||||
{
|
{
|
||||||
throw (new RetryableServerErrorException(qResponse.getContent()));
|
throw (new RetryableServerErrorException(statusCode, qResponse.getContent()));
|
||||||
}
|
}
|
||||||
else if(statusCode >= 400)
|
else if(statusCode >= 400)
|
||||||
{
|
{
|
||||||
@ -970,7 +970,7 @@ public class BaseAPIActionUtil
|
|||||||
throw (new QException(see));
|
throw (new QException(see));
|
||||||
}
|
}
|
||||||
|
|
||||||
LOG.info("Caught Server-side error during API request", logPair("serverErrorsCaught", serverErrorsCaught), logPair("uri", request.getURI()), logPair("table", table.getName()), logPair("sleeping", serverErrorsSleepMillis));
|
LOG.info("Caught Server-side error during API request", logPair("serverErrorsCaught", serverErrorsCaught), logPair("uri", request.getURI()), logPair("code", see.getCode()), logPair("table", table.getName()), logPair("sleeping", serverErrorsSleepMillis));
|
||||||
SleepUtils.sleep(serverErrorsSleepMillis, TimeUnit.MILLISECONDS);
|
SleepUtils.sleep(serverErrorsSleepMillis, TimeUnit.MILLISECONDS);
|
||||||
serverErrorsSleepMillis *= 2;
|
serverErrorsSleepMillis *= 2;
|
||||||
}
|
}
|
||||||
@ -995,7 +995,7 @@ public class BaseAPIActionUtil
|
|||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
**
|
**
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
private boolean shouldBeRetryableServerErrorException(QHttpResponse qResponse)
|
protected boolean shouldBeRetryableServerErrorException(QHttpResponse qResponse)
|
||||||
{
|
{
|
||||||
return (qResponse.getStatusCode() != null && qResponse.getStatusCode() >= 500);
|
return (qResponse.getStatusCode() != null && qResponse.getStatusCode() >= 500);
|
||||||
}
|
}
|
||||||
|
@ -30,13 +30,48 @@ import com.kingsrook.qqq.backend.core.exceptions.QException;
|
|||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
public class RetryableServerErrorException extends QException
|
public class RetryableServerErrorException extends QException
|
||||||
{
|
{
|
||||||
|
private Integer code;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
**
|
**
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
public RetryableServerErrorException(String message)
|
public RetryableServerErrorException(Integer code, String message)
|
||||||
{
|
{
|
||||||
super(message);
|
super(message);
|
||||||
|
this.code = code;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
** Getter for code
|
||||||
|
*******************************************************************************/
|
||||||
|
public Integer getCode()
|
||||||
|
{
|
||||||
|
return (this.code);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
** Setter for code
|
||||||
|
*******************************************************************************/
|
||||||
|
public void setCode(Integer code)
|
||||||
|
{
|
||||||
|
this.code = code;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
** Fluent setter for code
|
||||||
|
*******************************************************************************/
|
||||||
|
public RetryableServerErrorException withCode(Integer code)
|
||||||
|
{
|
||||||
|
this.code = code;
|
||||||
|
return (this);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user