Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(analytics): Simplify error code checking, uniformly across platforms #3191

Merged
merged 2 commits into from
Feb 8, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -438,22 +438,22 @@ private void submitEventsAndEndpoint(final JSONArray eventArray,
} catch (final AmazonServiceException amazonServiceException) {
// This is service level exception, we also have item level exception.
log.error("AmazonServiceException occurred during send of put event ", amazonServiceException);
final String errorCode = amazonServiceException.getErrorCode();
final int statusCode = amazonServiceException.getStatusCode();

// If the error is not a retryable error, delete the events from the local database.
// Else if the error is a retryable error, keep the events in the local database.
if (isRetryable(errorCode)) {
if (isRetryable(statusCode)) {
log.error(
String.format("AmazonServiceException: Unable to successfully deliver events to server. " +
"Events will be saved, error is likely recoverable. " +
"Response Status code: %s, Response Error Code: %s",
amazonServiceException.getStatusCode(), amazonServiceException.getErrorCode()),
statusCode, amazonServiceException.getErrorCode()),
amazonServiceException);
batchIdsAndSizeToDelete.clear();
} else {
log.error(
String.format(Locale.getDefault(), "Failed to submit events to EventService: statusCode: " +
amazonServiceException.getStatusCode() + " errorCode: ", errorCode),
statusCode + " errorCode: ", amazonServiceException.getErrorCode()),
amazonServiceException);
log.error(
String.format(Locale.getDefault(), "Failed submission of %d events, events will be " +
Expand Down Expand Up @@ -531,7 +531,7 @@ private void processEventsResponse(final JSONArray eventArray,
// so the event does not get deleted from the local database.
if (responseMessage.getMessage().equalsIgnoreCase("Accepted")) {
log.info(String.format("Successful submit event with event id %s", eventId));
} else if (isRetryable(responseMessage.getMessage())) {
} else if (isRetryable(responseMessage.getStatusCode())) {
log.warn(String.format("Unable to successfully deliver event to server. " +
"Event will be saved. Event id %s", eventId));
batchIdsAndSizeToDelete.remove(eventArray.getJSONObject(i).getInt(DATABASE_ID_KEY));
Expand All @@ -548,13 +548,8 @@ private void processEventsResponse(final JSONArray eventArray,
}
}

private boolean isRetryable(String responseCode) {
if (responseCode.equalsIgnoreCase("ValidationException") ||
responseCode.equalsIgnoreCase("SerializationException") ||
responseCode.equalsIgnoreCase("BadRequestException")) {
return false;
}
return true;
private boolean isRetryable(int httpCode) {
tjleing marked this conversation as resolved.
Show resolved Hide resolved
return httpCode >= 500 && httpCode <= 599;
}

private boolean isClientExceptionRetryable(Throwable amazonClientException) {
Expand Down