|
27 | 27 | import dev.openfeature.sdk.Reason; |
28 | 28 | import dev.openfeature.sdk.exceptions.FlagNotFoundError; |
29 | 29 | import dev.openfeature.sdk.exceptions.GeneralError; |
| 30 | +import dev.openfeature.sdk.exceptions.InvalidContextError; |
30 | 31 | import dev.openfeature.sdk.exceptions.OpenFeatureError; |
31 | 32 | import dev.openfeature.sdk.exceptions.TypeMismatchError; |
32 | 33 | import java.io.IOException; |
@@ -156,17 +157,23 @@ public <T> EvaluationResponse<T> evaluateFlag( |
156 | 157 | } |
157 | 158 |
|
158 | 159 | try (Response response = this.httpClient.newCall(reqBuilder.build()).execute()) { |
159 | | - if (response.code() == HttpURLConnection.HTTP_UNAUTHORIZED) { |
160 | | - throw new GeneralError("invalid token used to contact GO Feature Flag relay proxy instance"); |
161 | | - } |
162 | | - if (response.code() >= HttpURLConnection.HTTP_BAD_REQUEST) { |
163 | | - throw new GeneralError("impossible to contact GO Feature Flag relay proxy instance"); |
| 160 | + if (response.code() == HttpURLConnection.HTTP_UNAUTHORIZED |
| 161 | + || response.code() == HttpURLConnection.HTTP_FORBIDDEN) { |
| 162 | + throw new GeneralError("authentication/authorization error"); |
164 | 163 | } |
165 | 164 |
|
166 | 165 | ResponseBody responseBody = response.body(); |
167 | 166 | String body = responseBody != null ? responseBody.string() : ""; |
168 | 167 | GoFeatureFlagResponse goffResp = responseMapper.readValue(body, GoFeatureFlagResponse.class); |
169 | 168 |
|
| 169 | + if (response.code() == HttpURLConnection.HTTP_BAD_REQUEST) { |
| 170 | + throw new InvalidContextError("Invalid context " + goffResp.getMessage()); |
| 171 | + } |
| 172 | + |
| 173 | + if (response.code() == HttpURLConnection.HTTP_INTERNAL_ERROR) { |
| 174 | + throw new GeneralError("Unknown error while retrieving flag " + goffResp.getMessage()); |
| 175 | + } |
| 176 | + |
170 | 177 | if (Reason.DISABLED.name().equalsIgnoreCase(goffResp.getReason())) { |
171 | 178 | // we don't set a variant since we are using the default value, and we are not able to |
172 | 179 | // know |
|
0 commit comments