Repository navigation
feat(apidocs): Publish the SentryAPIException error body as a component - #131285
Merged
Merged
Conversation
Add a SentryApiErrorBody schema component that describes the
{"detail": {"code", "message", "extra"}} body SentryAPIException
subclasses send. It is built from the exception classes: one detail
variant per code, with its status in x-sentry-status and the string keys
its extra can carry.
Each class declares those keys in a new extra_keys attribute, and a test
checks them against what the class's __init__ passes. Operations don't
reference the component, since any operation can return these errors.
Co-Authored-By: BYK <[email protected]>
BYK
approved these changes
Nov 16, 2026
BYK
pushed a commit
that referenced
this pull request
Nov 16, 2026
…#131346) Part of #131203. Follow-up to #131285. `@sentry/api` (#131287) generates its error codes from the `SentryApiErrorBody` component, but it still hard-codes which codes are auth challenges, meaning errors the user clears by acting in Sentry (SSO, sudo, superuser, staff, 2FA, member-disabled, email verification). The spec can't say this today, and status doesn't tell them apart: `data-secrecy` is a 401 and `user-required` is a 403, and neither is a challenge. - `SentryAPIException` gets an `auth_challenge` class attribute, `True` on those seven classes. - Each `SentryApiErrorBody` variant publishes it as `x-sentry-auth-challenge`. - Every 401 and 403 subclass must set the attribute in its own class body, even to `False` (as `UserRequired` and `DataSecrecyError` do), so a new auth-related code needs an explicit decision and can't be left out of clients by accident. <!-- junior-session-footer:start --> <!-- junior-conversation-id:agent%3A9cddb8264df48e793bc61c15cd431e51 --> -- [View Session](https://junior-prod.sentry.dev/conversations/agent%3A9cddb8264df48e793bc61c15cd431e51) [[Sentry]](https://sentry.sentry.io/explore/conversations/agent%3A9cddb8264df48e793bc61c15cd431e51/?project=4510944073809921) <!-- junior-session-footer:end --> Co-authored-by: sentry-junior[bot] <264270552+sentry-junior[bot]@users.noreply.github.com>
BYK
added a commit
that referenced
this pull request
Nov 16, 2026
…131287) Part of #131203. Stacked on #131346, and it includes #131253's commits until that PR merges. #131253 added `KnownSentryErrorCode` and the auth-challenge fields to `@sentry/api` as hand-written copies of the backend's `SentryAPIException` classes, which can drift. #131285 publishes those classes as the spec's `SentryApiErrorBody` component, and #131346 marks the auth challenges in it, so the SDK now generates from it: - A new build step, `scripts/generate-error-codes.mjs`, reads the component with `ts.factory` into `SENTRY_ERROR_EXTRA_KEYS`, a code → `extra` keys table, and `SENTRY_AUTH_CHALLENGE_CODES`, the codes marked with `x-sentry-auth-challenge`. The build fails if the component is missing, an `extra` key isn't a string, or a variant has no boolean `x-sentry-auth-challenge`. - `KnownSentryErrorCode` is the table's keys. `SentryAuthChallenge` covers the marked codes, and each carries its fields from the table: `loginUrl` and `organizationSlug` for SSO, `orgSlug` for superuser, `username` for sudo and email verification, and `next` for a disabled member. `getSentryAuthChallenge` returns the same objects as before. - No code lists are left in the SDK. The README's list of challenge codes is checked against the spec. The known codes now also include the three Bitbucket webhook codes the backend defines. Nothing is removed from the public exports. <!-- junior-request-attribution:start --> via @BYK. <!-- junior-request-attribution:end --> <!-- junior-session-footer:start --> <!-- junior-conversation-id:agent%3A9cddb8264df48e793bc61c15cd431e51 --> -- [View Session](https://junior-prod.sentry.dev/conversations/agent%3A9cddb8264df48e793bc61c15cd431e51) [[Sentry]](https://sentry.sentry.io/explore/conversations/agent%3A9cddb8264df48e793bc61c15cd431e51/?project=4510944073809921) <!-- junior-session-footer:end --> --------- Co-authored-by: sentry-junior[bot] <264270552+sentry-junior[bot]@users.noreply.github.com> Co-authored-by: BYK <[email protected]>
joshuarli
added a commit
that referenced
this pull request
Nov 17, 2026
…31482) `tests/sentry/apidocs/test_error_codes.py` (added in #131285) reads `SentryAPIException` subclass source with `ast` instead of executing it, so selective selection can't map exception edits to it. This adds it to `ALWAYS_RUN_TESTS`, next to similar source-parsing entries. <!-- junior-request-attribution:start --> via @joshuarli. <!-- junior-request-attribution:end --> <!-- junior-session-footer:start --> <!-- junior-conversation-id:agent-dispatch%3Adispatch_c132b3c805770741e08a1a9c46962fb2 --> -- [View Session](https://junior-prod.sentry.dev/conversations/agent-dispatch%3Adispatch_c132b3c805770741e08a1a9c46962fb2) [[Sentry]](https://sentry.sentry.io/explore/conversations/agent-dispatch%3Adispatch_c132b3c805770741e08a1a9c46962fb2/?project=4510944073809921) <!-- junior-session-footer:end --> Co-authored-by: sentry-junior[bot] <264270552+sentry-junior[bot]@users.noreply.github.com> Co-authored-by: Joshua Li <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Part of #131203.
SentryAPIExceptionsubclasses answer with{"detail": {"code", "message", "extra"}}, but the OpenAPI spec doesn't describe that body.@sentry/api(#131253) keeps a hand-written list of the codes, which can drift from the backend. This adds aSentryApiErrorBodyschema component so clients can generate from the spec instead.SentryAPIExceptionsubclass with a code. Each one becomes adetailvariant with itscode(a one-value enum), its HTTP status inx-sentry-status, and the string keys itsextracan carry. Two classes that share a code with different statuses fail the build.extrakeys.SentryAPIExceptiongets anextra_keysclass attribute, set where the keys are stable:sso-required(loginUrl,organizationSlug),sudo-requiredandprimary-email-verification-required(username),member-disabled-over-limit(next),parameter-validation-error(context), andsuperuser-required(orgSlug, which only organization-scoped checks send). Each class'sextra_keysmust match the keywords its__init__passes tosuper().__init__, so a new key there has to be declared.The variants also include the Bitbucket webhook codes, since those classes are
SentryAPIExceptionsubclasses too.ImageTooLargeandFileTooLargesend an empty code, so they're left out.Next: an
@sentry/apiPR that generatesKnownSentryErrorCodeand the auth-challenge fields from this component.via @BYK.
--
View Session [Sentry]