Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

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 @@ -142,7 +142,7 @@ public <T> EvaluationResponse<T> evaluateFlag(
requestMapper.writeValueAsBytes(goffRequest),
MediaType.get("application/json; charset=utf-8")));

if (this.apiKey != null && !"".equals(this.apiKey)) {
if (this.apiKey != null && !this.apiKey.isEmpty()) {
reqBuilder.addHeader(HttpHeaders.AUTHORIZATION, BEARER_TOKEN + this.apiKey);
}

Expand Down Expand Up @@ -299,6 +299,10 @@ public ConfigurationChange configurationHasChanged() throws GoFeatureFlagExcepti
* @return an item from the enum
*/
private ErrorCode mapErrorCode(String errorCode) {
if (errorCode == null || errorCode.isEmpty()) {
return null;
}

try {
return ErrorCode.valueOf(errorCode);
} catch (IllegalArgumentException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,24 @@ void should_resolve_a_valid_boolean_flag_with_TARGETING_MATCH_reason() {
assertEquals(want, got);
}

@SneakyThrows
@Test
void should_resolve_a_valid_boolean_flag_with_TARGETING_MATCH_reason_without_error_code_in_payload() {
GoFeatureFlagProvider g = new GoFeatureFlagProvider(GoFeatureFlagProviderOptions.builder().endpoint(this.baseUrl.toString()).timeout(1000).build());
String providerName = this.testName;
OpenFeatureAPI.getInstance().setProviderAndWait(providerName, g);
Client client = OpenFeatureAPI.getInstance().getClient(providerName);
FlagEvaluationDetails<Boolean> got = client.getBooleanDetails("bool_targeting_match_no_error_code", false, this.evaluationContext);
FlagEvaluationDetails<Boolean> want = FlagEvaluationDetails.<Boolean>builder()
.value(true)
.variant("True")
.flagKey("bool_targeting_match_no_error_code")
.reason(Reason.TARGETING_MATCH.name())
.flagMetadata(defaultMetadata)
.build();
assertEquals(want, got);
}

@SneakyThrows
@Test
void should_resolve_a_valid_boolean_flag_with_TARGETING_MATCH_reason_cache_disabled() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"trackEvents": true,
"variationType": "True",
"failed": false,
"version": 0,
"reason": "TARGETING_MATCH",
"value": true,
"cacheable": true,
"metadata": {
"pr_link": "https://github.com/thomaspoignant/go-feature-flag/pull/916",
"version": 1
}
}