Skip to content

Commit

Permalink
Using generic error message in place of custom error message
Browse files Browse the repository at this point in the history
  • Loading branch information
mishprs committed Aug 30, 2023
1 parent d98732c commit e21ea73
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.opensearch.search.relevance.transformer.personalizeintelligentranking.configuration.PersonalizeIntelligentRankerConfiguration;
import org.opensearch.search.relevance.transformer.personalizeintelligentranking.requestparameter.PersonalizeRequestParameters;
import org.opensearch.search.relevance.transformer.personalizeintelligentranking.reranker.PersonalizedRanker;
import org.opensearch.search.relevance.transformer.personalizeintelligentranking.utils.ValidationUtil;

import java.util.ArrayList;
import java.util.Arrays;
Expand All @@ -37,8 +38,7 @@ public class AmazonPersonalizedRankerImpl implements PersonalizedRanker {
private static final Logger logger = LogManager.getLogger(AmazonPersonalizedRankerImpl.class);
private final PersonalizeIntelligentRankerConfiguration rankerConfig;
private final PersonalizeClient personalizeClient;
private static final String INSUFFCIENT_PERMISSION_ERROR_MESSAGE =
"Insufficient privileges for calling personalize service. Please ensure that the supplied role is configured correctly.";

public AmazonPersonalizedRankerImpl(PersonalizeIntelligentRankerConfiguration config,
PersonalizeClient client) {
this.rankerConfig = config;
Expand Down Expand Up @@ -102,8 +102,8 @@ public SearchHits rerank(SearchHits hits, PersonalizeRequestParameters requestPa
} catch (AmazonServiceException e) {
logger.error("Exception while calling personalize campaign: {}", e.getMessage());
int statusCode = e.getStatusCode();
if (statusCode >= 400 && statusCode < 500) {
throw new IllegalArgumentException(INSUFFCIENT_PERMISSION_ERROR_MESSAGE);
if (ValidationUtil.is4xxError(statusCode)) {
throw new IllegalArgumentException(e);
}
throw e;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,11 @@ private static boolean isValidCampaignOrRoleArn(String arn, String expectedServi
return false;
}
}

public static boolean is4xxError(int statusCode){
if (statusCode >= 400 && statusCode < 500) {
return true;
}
return false;
}
}

0 comments on commit e21ea73

Please sign in to comment.