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

Conversation

gogbog
Copy link
Contributor

@gogbog gogbog commented Feb 26, 2025

Description

The pull request improves error handling for the Python provider.

Currently, the error message is hardcoded. With this update, if a message parameter is sent in the response, it will be displayed."

Let me know if you'd like further refinements!

Copy link

netlify bot commented Feb 26, 2025

Deploy Preview for go-feature-flag-doc-preview ready!

Name Link
🔨 Latest commit 7e303a8
🔍 Latest deploy log https://app.netlify.com/sites/go-feature-flag-doc-preview/deploys/67cb44effff3f90008cd580e
😎 Deploy Preview https://deploy-preview-3147--go-feature-flag-doc-preview.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link

codecov bot commented Feb 26, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 84.95%. Comparing base (b4cc91a) to head (7e303a8).
Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #3147   +/-   ##
=======================================
  Coverage   84.95%   84.95%           
=======================================
  Files         113      113           
  Lines        5276     5276           
=======================================
  Hits         4482     4482           
  Misses        630      630           
  Partials      164      164           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@gogbog gogbog changed the title handle 400 error with response message feat: handle 400 error with response message Feb 26, 2025
Copy link
Owner

@thomaspoignant thomaspoignant left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gogbog Thanks for this pull request, this is really great.

💭 thought: ‏I think we should add a unit test to validate that it works as expected.
If you don't have time to work on it, let me know and I will do it.

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤓 nitpick: ‏to follow the rest of the naming convention it will be better to name the variable error_message.

@gogbog
Copy link
Contributor Author

gogbog commented Mar 6, 2025

@gogbog Thanks for this pull request, this is really great.

💭 thought: ‏I think we should add a unit test to validate that it works as expected. If you don't have time to work on it, let me know and I will do it.

Thank you for your quick response. I considered writing tests, but I'm not sure at the moment how to trigger a 400 error from the GOFF side. The OFREP endpoints have more mature error handling, but in v1, it seems that errors only occur if the evaluation context is empty or if the key is not found in the body - both of which are already handled by the provider even before sending the request.

The main purpose of this PR is to make the provider more future-proof (e.g., for a potential migration to OFREP). Additionally, we have a wrapper for GOFF that adds extra logic and validations, returning a 400 error with a message. However, this message is not properly handled in the Python provider.

Let me know if you have any ideas on how we can test this, as I'm not completely sure at the moment.

@thomaspoignant
Copy link
Owner

Ok got it, that's true that this is not easy to handle this.
I will merge it as is 👌

Copy link

sonarqubecloud bot commented Mar 7, 2025

@kodiakhq kodiakhq bot merged commit 5caf22c into thomaspoignant:main Mar 7, 2025
23 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants