Skip to content

Commit

Permalink
Fixed exception wrapping.
Browse files Browse the repository at this point in the history
Signed-off-by: AWSHurneyt <[email protected]>
  • Loading branch information
AWSHurneyt committed Jul 18, 2024
1 parent fe8e546 commit 269acbf
Showing 1 changed file with 60 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,67 @@ public void downloadAndIndexIOCs(SATIFSourceConfig saTifSourceConfig, ActionList

try {
s3Connector.load(consumer);
} catch (NoSuchKeyException e) {
log.warn("Failed to load IOCs from S3 with NoSuchKeyException: ", e);
listener.onFailure(
new SecurityAnalyticsException(
"Failed to load IOCs from S3 with NoSuchKeyException: ",
RestStatus.fromCode(e.statusCode()),
e
));
return;
} catch (S3Exception e) {
log.warn("Failed to load IOCs from S3 with S3Exception: ", e);
listener.onFailure(
new SecurityAnalyticsException(
"Failed to load IOCs from S3 with S3Exception: ",
RestStatus.fromCode(e.statusCode()),
e
));
return;
} catch (StsException e) {
log.warn("Failed to load IOCs from S3 with StsException: ", e);
listener.onFailure(
new SecurityAnalyticsException(
"Failed to load IOCs from S3 with StsException: ",
RestStatus.fromCode(e.statusCode()),
e
));
return;
} catch (SdkException e) {
// SdkException is a RunTimeException that doesn't have a status code.
// Logging the full exception, and providing generic response as output.
log.warn("Failed to load IOCs from S3 with SdkException: ", e);
listener.onFailure(
new SecurityAnalyticsException(
"Failed to load IOCs from S3 with SdkException: ",
RestStatus.FORBIDDEN,
e
));
return;
} catch (AmazonServiceException e) {
log.warn("Failed to load IOCs from S3 with AmazonServiceException: ", e);
listener.onFailure(
new SecurityAnalyticsException(
"Failed to load IOCs from S3 with AmazonServiceException: ",
RestStatus.fromCode(e.getStatusCode()),
e
));
return;
} catch (SdkClientException e) {
// SdkException is a RunTimeException that doesn't have a status code.
// Logging the full exception, and providing generic response as output.
log.warn("Failed to load IOCs from S3 with SdkClientException: ", e);
listener.onFailure(
new SecurityAnalyticsException(
"Failed to load IOCs from S3 with SdkClientException: ",
RestStatus.FORBIDDEN,
e
));
return;
} catch (Exception e) {
log.error("Failed to download IOCs.", e);
listener.onFailure(e);
log.warn("Failed to load IOCs from S3 with error: ", e);
listener.onFailure(SecurityAnalyticsException.wrap(e));
return;
}

Expand Down Expand Up @@ -169,7 +227,6 @@ private void testS3ClientConnection(S3ConnectorConfig s3ConnectorConfig, ActionL
log.warn("S3Client connection test failed with error: ", e);
listener.onFailure(SecurityAnalyticsException.wrap(e));
}

}

private void testAmazonS3Connection(S3ConnectorConfig s3ConnectorConfig, ActionListener<TestS3ConnectionResponse> listener) {
Expand Down

0 comments on commit 269acbf

Please sign in to comment.