Commit 32333c6
fix(rpc): fix seer RPC exception handling to default to 500 and preserve rest APIException (#112435)
<!-- CURSOR_AGENT_PR_BODY_BEGIN -->
## Problem
When Seer makes RPC calls to Sentry and encounters downstream errors
(like 429 rate limits or 500 errors from Snuba), the current code
catches all exceptions and re-raises them as `ValidationError` (400).
This misrepresents the actual issue, making it appear as if the client
sent bad request parameters when the real cause is a downstream service
error.
Example issue:
https://sentry.dev.getsentry.net:7999/issues/7380803020/events/d3e6e1d5ddf44d7b94c86e6ce2435ea6/
## Solution
This PR fixes the exception handling in the seer RPC endpoint to raise a
generic 500 APIException by default, implying an error happened on
sentry server. Also re-raises APIException's (base class for rest
framework excs) so developers can bubble their own status codes up to
response for Seer.
1. **Added a handler to re-raise REST framework exceptions directly** -
Any `APIException` (which includes `Throttled`, custom API exceptions,
etc.) is now re-raised as-is, preserving its status code
2. **Changed generic exception handler to raise `APIException` (500)
instead of `ValidationError` (400)** - Unknown errors now correctly
return 500 Internal Server Error instead of 400 Bad Request
### Changes
- Modified `SeerRpcServiceEndpoint.post()` in
`src/sentry/seer/endpoints/seer_rpc.py`:
- Added `except APIException: raise` handler before the generic
exception handler
- Changed `raise ValidationError from e` to `raise APIException from e`
for generic exceptions
- Added test cases in `tests/sentry/seer/endpoints/test_seer_rpc.py`:
- `test_rest_framework_exceptions_are_reraised` - verifies custom API
exceptions preserve their status codes
- `test_generic_exceptions_return_500` - verifies generic exceptions
return 500 instead of 400
## Testing
Pre-commit checks pass ✅
<!-- CURSOR_AGENT_PR_BODY_END -->
[Slack
Thread](https://sentry.slack.com/archives/C0AAF0JD0GK/p1775600719171269?thread_ts=1775600719.171269&cid=C0AAF0JD0GK)
<div><a
href="https://cursor.com/agents/bc-8bf9c0b1-d369-5efa-81a7-a650bb7e83cc"><picture><source
media="(prefers-color-scheme: dark)"
srcset="https://cursor.com/assets/images/open-in-web-dark.png"><source
media="(prefers-color-scheme: light)"
srcset="https://cursor.com/assets/images/open-in-web-light.png"><img
alt="Open in Web" width="114" height="28"
src="https://cursor.com/assets/images/open-in-web-dark.png"></picture></a> <a
href="https://cursor.com/background-agent?bcId=bc-8bf9c0b1-d369-5efa-81a7-a650bb7e83cc"><picture><source
media="(prefers-color-scheme: dark)"
srcset="https://cursor.com/assets/images/open-in-cursor-dark.png"><source
media="(prefers-color-scheme: light)"
srcset="https://cursor.com/assets/images/open-in-cursor-light.png"><img
alt="Open in Cursor" width="131" height="28"
src="https://cursor.com/assets/images/open-in-cursor-dark.png"></picture></a> </div>
---------
Co-authored-by: Cursor Agent <cursoragent@cursor.com>
Co-authored-by: Andrew Liu <aliu39@users.noreply.github.com>1 parent a6cee27 commit 32333c6
File tree
2 files changed
+47
-1
lines changed- src/sentry/seer/endpoints
- tests/sentry/seer/endpoints
2 files changed
+47
-1
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
271 | 271 | | |
272 | 272 | | |
273 | 273 | | |
| 274 | + | |
| 275 | + | |
274 | 276 | | |
275 | 277 | | |
276 | 278 | | |
277 | 279 | | |
278 | 280 | | |
279 | 281 | | |
280 | | - | |
| 282 | + | |
281 | 283 | | |
282 | 284 | | |
283 | 285 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
87 | 87 | | |
88 | 88 | | |
89 | 89 | | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
90 | 134 | | |
91 | 135 | | |
92 | 136 | | |
| |||
0 commit comments