Skip to content

feat: handle 400 error with response message #3147

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

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 @@ -19,6 +19,7 @@
ErrorCode,
FlagNotFoundError,
GeneralError,
InvalidContextError,
OpenFeatureError,
TypeMismatchError,
)
Expand Down Expand Up @@ -210,16 +211,29 @@ def generic_go_feature_flag_resolver(
body=goff_request.model_dump_json(),
)

response_body = response.data

# Handle 404 error code
if response.status == HTTPStatus.NOT_FOUND.value:
raise FlagNotFoundError(
"flag {} was not found in your configuration".format(flag_key)
)

if int(response.status) >= HTTPStatus.BAD_REQUEST.value:
# Handle 400 error code
if int(response.status) == HTTPStatus.BAD_REQUEST.value:
response_dict = json.loads(response_body)
error_message = response_dict.get("message")

if error_message is None:
error_message = "no error message given."

raise InvalidContextError("Invalid context: " + error_message)

# Handle every error response above 400
if int(response.status) > HTTPStatus.BAD_REQUEST.value:
raise GeneralError(
"impossible to contact GO Feature Flag relay proxy instance"
)
response_body = response.data

response_flag_evaluation = ResponseFlagEvaluation.model_validate_json(
response_body
Expand Down
Loading