Skip to content

Commit 5caf22c

Browse files
gogbogGeorgi Dimitrovthomaspoignant
authored
feat: handle 400 error with response message (#3147)
* handle 400 error with response message * remove logs and todos * fix lint * follow the same naming conventions as the rest of the project --------- Co-authored-by: Georgi Dimitrov <[email protected]> Co-authored-by: Thomas Poignant <[email protected]>
1 parent b4cc91a commit 5caf22c

File tree

1 file changed

+16
-2
lines changed
  • openfeature/providers/python-provider/gofeatureflag_python_provider

1 file changed

+16
-2
lines changed

openfeature/providers/python-provider/gofeatureflag_python_provider/provider.py

+16-2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
ErrorCode,
2020
FlagNotFoundError,
2121
GeneralError,
22+
InvalidContextError,
2223
OpenFeatureError,
2324
TypeMismatchError,
2425
)
@@ -210,16 +211,29 @@ def generic_go_feature_flag_resolver(
210211
body=goff_request.model_dump_json(),
211212
)
212213

214+
response_body = response.data
215+
216+
# Handle 404 error code
213217
if response.status == HTTPStatus.NOT_FOUND.value:
214218
raise FlagNotFoundError(
215219
"flag {} was not found in your configuration".format(flag_key)
216220
)
217221

218-
if int(response.status) >= HTTPStatus.BAD_REQUEST.value:
222+
# Handle 400 error code
223+
if int(response.status) == HTTPStatus.BAD_REQUEST.value:
224+
response_dict = json.loads(response_body)
225+
error_message = response_dict.get("message")
226+
227+
if error_message is None:
228+
error_message = "no error message given."
229+
230+
raise InvalidContextError("Invalid context: " + error_message)
231+
232+
# Handle every error response above 400
233+
if int(response.status) > HTTPStatus.BAD_REQUEST.value:
219234
raise GeneralError(
220235
"impossible to contact GO Feature Flag relay proxy instance"
221236
)
222-
response_body = response.data
223237

224238
response_flag_evaluation = ResponseFlagEvaluation.model_validate_json(
225239
response_body

0 commit comments

Comments
 (0)