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 c3f386e commit fe8e546
Showing 1 changed file with 7 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import org.apache.commons.csv.CSVRecord;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.opensearch.OpenSearchStatusException;
import org.opensearch.action.bulk.BulkRequest;
import org.opensearch.client.Client;
import org.opensearch.cluster.service.ClusterService;
Expand Down Expand Up @@ -111,7 +112,7 @@ public void onlyIndexIocs(SATIFSourceConfig saTifSourceConfig,
feedStore.indexIocs(stix2IOCList);
} catch (Exception e) {
log.error("Failed to index IOCs from source config", e);
listener.onFailure(SecurityAnalyticsException.wrap(e));
listener.onFailure(e);
}
}

Expand All @@ -125,15 +126,15 @@ public void downloadAndIndexIOCs(SATIFSourceConfig saTifSourceConfig, ActionList
s3Connector.load(consumer);
} catch (Exception e) {
log.error("Failed to download IOCs.", e);
listener.onFailure(SecurityAnalyticsException.wrap(e));
listener.onFailure(e);
return;
}

try {
consumer.flushIOCs();
} catch (Exception e) {
log.error("Failed to flush IOCs queue.", e);
listener.onFailure(SecurityAnalyticsException.wrap(e));
listener.onFailure(e);
}
}

Expand Down Expand Up @@ -221,11 +222,11 @@ private S3ConnectorConfig constructS3ConnectorConfig(SATIFSourceConfig saTifSour

private void validateS3ConnectorConfig(S3ConnectorConfig s3ConnectorConfig) {
if (s3ConnectorConfig.getRoleArn() == null || s3ConnectorConfig.getRoleArn().isEmpty()) {
throw new IllegalArgumentException("Role arn is required.");
throw new SecurityAnalyticsException("Role arn is required.", RestStatus.BAD_REQUEST, new IllegalArgumentException());
}

if (s3ConnectorConfig.getRegion() == null || s3ConnectorConfig.getRegion().isEmpty()) {
throw SecurityAnalyticsException.wrap(new IllegalArgumentException("Region is required."));
throw new SecurityAnalyticsException("Region is required.", RestStatus.BAD_REQUEST, new IllegalArgumentException());
}

if (s3ConnectorConfig.getRegion().length() > MAX_REGION_LENGTH) {
Expand All @@ -236,7 +237,7 @@ private void validateS3ConnectorConfig(S3ConnectorConfig s3ConnectorConfig) {
MAX_REGION_LENGTH
);
log.error(error);
throw SecurityAnalyticsException.wrap(new IllegalArgumentException(error));
throw new SecurityAnalyticsException(error, RestStatus.BAD_REQUEST, new IllegalArgumentException());
}
}

Expand Down

0 comments on commit fe8e546

Please sign in to comment.