diff --git a/providers/go-feature-flag/src/main/java/dev/openfeature/contrib/providers/gofeatureflag/bean/GoFeatureFlagResponse.java b/providers/go-feature-flag/src/main/java/dev/openfeature/contrib/providers/gofeatureflag/bean/GoFeatureFlagResponse.java index 79e2c99b5..4d8274725 100644 --- a/providers/go-feature-flag/src/main/java/dev/openfeature/contrib/providers/gofeatureflag/bean/GoFeatureFlagResponse.java +++ b/providers/go-feature-flag/src/main/java/dev/openfeature/contrib/providers/gofeatureflag/bean/GoFeatureFlagResponse.java @@ -12,6 +12,7 @@ public class GoFeatureFlagResponse { private String version; private String reason; private String errorCode; + private String message; private Object value; private Boolean cacheable; private Map metadata; diff --git a/providers/go-feature-flag/src/main/java/dev/openfeature/contrib/providers/gofeatureflag/controller/GoFeatureFlagController.java b/providers/go-feature-flag/src/main/java/dev/openfeature/contrib/providers/gofeatureflag/controller/GoFeatureFlagController.java index c39bfee4b..e2ca9f00c 100644 --- a/providers/go-feature-flag/src/main/java/dev/openfeature/contrib/providers/gofeatureflag/controller/GoFeatureFlagController.java +++ b/providers/go-feature-flag/src/main/java/dev/openfeature/contrib/providers/gofeatureflag/controller/GoFeatureFlagController.java @@ -27,6 +27,7 @@ import dev.openfeature.sdk.Reason; import dev.openfeature.sdk.exceptions.FlagNotFoundError; import dev.openfeature.sdk.exceptions.GeneralError; +import dev.openfeature.sdk.exceptions.InvalidContextError; import dev.openfeature.sdk.exceptions.OpenFeatureError; import dev.openfeature.sdk.exceptions.TypeMismatchError; import java.io.IOException; @@ -156,17 +157,23 @@ public EvaluationResponse evaluateFlag( } try (Response response = this.httpClient.newCall(reqBuilder.build()).execute()) { - if (response.code() == HttpURLConnection.HTTP_UNAUTHORIZED) { - throw new GeneralError("invalid token used to contact GO Feature Flag relay proxy instance"); - } - if (response.code() >= HttpURLConnection.HTTP_BAD_REQUEST) { - throw new GeneralError("impossible to contact GO Feature Flag relay proxy instance"); + if (response.code() == HttpURLConnection.HTTP_UNAUTHORIZED + || response.code() == HttpURLConnection.HTTP_FORBIDDEN) { + throw new GeneralError("authentication/authorization error"); } ResponseBody responseBody = response.body(); String body = responseBody != null ? responseBody.string() : ""; GoFeatureFlagResponse goffResp = responseMapper.readValue(body, GoFeatureFlagResponse.class); + if (response.code() == HttpURLConnection.HTTP_BAD_REQUEST) { + throw new InvalidContextError("Invalid context " + goffResp.getMessage()); + } + + if (response.code() == HttpURLConnection.HTTP_INTERNAL_ERROR) { + throw new GeneralError("Unknown error while retrieving flag " + goffResp.getMessage()); + } + if (Reason.DISABLED.name().equalsIgnoreCase(goffResp.getReason())) { // we don't set a variant since we are using the default value, and we are not able to // know diff --git a/providers/go-feature-flag/src/test/java/dev/openfeature/contrib/providers/gofeatureflag/GoFeatureFlagProviderTest.java b/providers/go-feature-flag/src/test/java/dev/openfeature/contrib/providers/gofeatureflag/GoFeatureFlagProviderTest.java index 38a81c60b..7c34fd927 100644 --- a/providers/go-feature-flag/src/test/java/dev/openfeature/contrib/providers/gofeatureflag/GoFeatureFlagProviderTest.java +++ b/providers/go-feature-flag/src/test/java/dev/openfeature/contrib/providers/gofeatureflag/GoFeatureFlagProviderTest.java @@ -238,7 +238,7 @@ void should_throw_an_error_if_endpoint_not_available() { .value(false) .reason(Reason.ERROR.name()) .errorCode(ErrorCode.GENERAL) - .errorMessage("impossible to contact GO Feature Flag relay proxy instance") + .errorMessage("unknown error while retrieving flag fail_500") .build(); assertEquals(want, got); } @@ -259,7 +259,7 @@ void should_throw_an_error_if_invalid_api_key() { .value(false) .reason(Reason.ERROR.name()) .errorCode(ErrorCode.GENERAL) - .errorMessage("invalid token used to contact GO Feature Flag relay proxy instance") + .errorMessage("authentication/authorization error") .build(); assertEquals(want, got); }