feat: better communicate limits in Core API errors - #8206
Conversation
- Introduced specific `402 Payment Required` exceptions for paywall and plan limits (replacing generic 400 Bad Request errors). - Updated organization invite views to return 402 when seat limits are exceeded. - Updated project edge migration views to return 402 when project size limits (identities, features, segments) are exceeded. - Standardized error detail messages to include direct links to pricing and support documentation. - Updated all related unit tests in `test_unit_invites_views.py` and `test_unit_projects_views.py` to assert the new 402 status codes and updated detail strings.
|
@srijantrpth is attempting to deploy a commit to the Flagsmith Team on Vercel. A member of the Team first needs to authorize it. |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Pro Plus Run ID: 📒 Files selected for processing (5)
📝 WalkthroughWalkthroughOrganisation and subscription plan errors now return HTTP 402 with the Estimated code review effort: 3 (Moderate) | ~20 minutes ✨ Finishing Touches 💡 1🛠️ Fix failing CI checks 💡
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
for more information, see https://pre-commit.ci
There was a problem hiding this comment.
Pull request overview
This PR standardises Core API error responses for plan-gated limits vs adjustable system limits, aiming to provide clearer guidance (pricing vs support) to API clients and end users.
Changes:
- Updated subscription / organisation exceptions to use
402 Payment Requiredfor plan-gated limits and include pricing guidance in the human-readable detail. - Introduced a
SystemLimitErrorbase exception for project “size / count” limits with updated support guidance, and updated related unit tests to assert the new detail strings. - Refreshed unit tests for invite-seat limit and project migration limit scenarios to match the new status codes / messages.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| api/tests/unit/projects/test_unit_projects_views.py | Updates assertions for “system limit” project migration failures to use the new support-directed detail strings. |
| api/tests/unit/organisations/invites/test_unit_invites_views.py | Updates assertions for seat-limit failures to return 402 and include the pricing URL in the detail message. |
| api/projects/exceptions.py | Adds a SystemLimitError base class and updates project limit exceptions to inherit it / use support-directed messaging. |
| api/organisations/subscriptions/exceptions.py | Introduces a base “invalid plan” exception with 402 + invalid-plan default code and pricing-directed detail; uses it for seat upgrade gating. |
| api/organisations/exceptions.py | Updates “no paid subscription” to be treated as an “invalid plan” style error (402 + pricing-directed detail). |
Suppressed comments (4)
api/tests/unit/organisations/invites/test_unit_invites_views.py:144
- This test now asserts 402 Payment Required, but the test name still says "returns_400". Renaming the test keeps the test intent accurate and makes failures easier to interpret.
assert response.status_code == status.HTTP_402_PAYMENT_REQUIRED
api/tests/unit/organisations/invites/test_unit_invites_views.py:298
- This test now asserts 402 Payment Required, but the test name still says "returns_400". Renaming the test keeps the test intent accurate and makes failures easier to interpret.
assert response.status_code == status.HTTP_402_PAYMENT_REQUIRED
api/tests/unit/organisations/invites/test_unit_invites_views.py:371
- This test now asserts 402 Payment Required, but the test name still says "returns_400". Renaming the test keeps the test intent accurate and makes failures easier to interpret.
assert response.status_code == status.HTTP_402_PAYMENT_REQUIRED
api/tests/unit/organisations/invites/test_unit_invites_views.py:403
- This test now asserts 402 Payment Required, but the test name still says "returns_400". Renaming the test keeps the test intent accurate and makes failures easier to interpret.
assert response.status_code == status.HTTP_402_PAYMENT_REQUIRED
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Actionable comments posted: 4
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro Plus
Run ID: 14b4a46e-15ae-4213-80a4-11314de6ccc1
📒 Files selected for processing (5)
api/organisations/exceptions.pyapi/organisations/subscriptions/exceptions.pyapi/projects/exceptions.pyapi/tests/unit/organisations/invites/test_unit_invites_views.pyapi/tests/unit/projects/test_unit_projects_views.py
- Added a custom DRF exception handler in `api/app/exceptions.py` to ensure `default_code` is exposed in the JSON response payload. - Removed duplicated imports and duplicated exception class definitions in `api/projects/exceptions.py`. - Renamed invite tests in `test_unit_invites_views.py` to accurately reflect the new `402` status code. - Added assertions for `"code": "invalid-plan"` and `"code": "system-limit"` across invite and project unit tests to verify the new handler works as expected.
for more information, see https://pre-commit.ci
|
Hi @srijantrpth, thanks for the contribution. I'm sorry, but we do not accept PRs for issues that relate to payments. |
Thanks for submitting a PR! Please check the boxes below:
docs/if required so people know about the feature.Changes
Closes #8130
Standardized Core API errors to better communicate limits and gates to API clients:
402 Payment Required, contain"code": "invalid-plan", and direct users tohttps://www.flagsmith.com/pricingin the human-readable description.400 Bad Request, contain"code": "system-limit", and direct users tohttps://docs.flagsmith.com/support#getting-in-touchin the human-readable description.How did you test this code?
tests/unit/organisations/invites/test_unit_invites_views.pyto assert402 Payment Required, the"invalid-plan"code, and the new pricing detail strings for seat limit violations.tests/unit/projects/test_unit_projects_views.pyto assert400 Bad Request, the"system-limit"code, and the updated support detail strings for project size limit violations.pytestto ensure 100% passing tests for both updated domains.