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:
Tim Chamberlain
2023-05-30 14:04:30 -05:00
parent 343f3fe01a
commit a5387ff9db
2 changed files with 40 additions and 5 deletions

View File

@ -514,7 +514,7 @@ public class BaseAPIActionUtil
{
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, "...")));
didLog = true;
@ -918,7 +918,7 @@ public class BaseAPIActionUtil
}
else if(shouldBeRetryableServerErrorException(qResponse))
{
throw (new RetryableServerErrorException(qResponse.getContent()));
throw (new RetryableServerErrorException(statusCode, qResponse.getContent()));
}
else if(statusCode >= 400)
{
@ -970,7 +970,7 @@ public class BaseAPIActionUtil
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);
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);
}

View File

@ -30,13 +30,48 @@ import com.kingsrook.qqq.backend.core.exceptions.QException;
*******************************************************************************/
public class RetryableServerErrorException extends QException
{
private Integer code;
/*******************************************************************************
**
*******************************************************************************/
public RetryableServerErrorException(String message)
public RetryableServerErrorException(Integer code, String 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);
}
}