Repository navigation
ref(api): Drop the isRecord guard from SentryApiError body reads - #131394
Merged
Merged
Conversation
SentryAPIException bodies, {"detail": {"code", "message", "extra"}},
now set code, detailMessage and extra on SentryApiError and its
subclasses. message stays the error's own, and other bodies leave the
fields unset. KnownSentryErrorCode lists the backend's codes, and
SentryErrorCode allows any other string. isSentryErrorCode narrows by
code.
getSentryAuthChallenge classifies SSO, sudo, superuser, staff, 2FA,
disabled-member and email-verification responses as data. The
withAuthChallenges fetch wrapper calls an onAuthChallenge handler and
replays the request once when it returns retry. The SDK opens no UI
and never redirects, and without the wrapper nothing is retried.
Co-Authored-By: BYK <[email protected]>
Co-Authored-By: BYK <[email protected]> # Conflicts: # static/packages/api/build.mjs # static/packages/api/lib/sentry-errors.ts
The /client core passed no body to createApiError when an error's detail was not a string, so SentryAPIException responses never set code on /client errors. Pass the parsed body. Report the superuser-required orgSlug extra on the challenge, and do not let a failed cancel of the challenge body stop the replay.
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]>
…rated-error-codes Co-Authored-By: BYK <[email protected]>
KnownSentryErrorCode and the auth-challenge extra fields were hand-maintained copies of the backend's SentryAPIException classes. A new build step reads the spec's SentryApiErrorBody component into SENTRY_ERROR_EXTRA_KEYS, and both types now derive from it. getSentryAuthChallenge reads each challenge's fields from the same table and returns the same objects as before. Co-Authored-By: BYK <[email protected]>
Clients had to hard-code which SentryAPIException codes the user can clear by acting in Sentry, such as sso-required or sudo-required. Status alone doesn't tell them apart: data-secrecy is a 401 and user-required a 403, and neither is one. Add an auth_challenge class attribute, publish it as x-sentry-auth-challenge on each SentryApiErrorBody variant, and require every 401 and 403 subclass to set it explicitly, so a new code can't be left out by accident.
…ted-error-codes # Conflicts: # src/sentry/api/exceptions.py # src/sentry/apidocs/error_codes.py # tests/sentry/apidocs/test_error_codes.py
getSentryAuthChallenge still listed its seven codes by hand. The generator now also emits SENTRY_AUTH_CHALLENGE_CODES, the codes the spec's SentryApiErrorBody marks with x-sentry-auth-challenge, and fails when a variant doesn't say. SentryAuthChallenge and the classifier use that list, and a test checks the README names the same codes.
Some endpoints document a code enum in their own error responses instead of using a SentryAPIException body, such as the Seer autofix 402 (seer_out_of_credits, seer_out_of_quota) and 409. The generator now collects those into SentryOperationErrorCode, deduped against the SentryApiErrorBody codes, and KnownSentryErrorCode includes them. Those bodies send code at the top level, so SentryApiError.code falls back to a top-level string code, with detailMessage from a string detail and an empty extra, when there is no SentryAPIException detail. SentryAPIException bodies read as before. Co-Authored-By: BYK <[email protected]>
Narrow the error body with typeof and `in` checks instead of the local isRecord type predicate, so TypeScript checks each read. extra is copied with Object.fromEntries to get a Record<string, unknown> without a cast. Results stay the same, and a test pins that a non-object extra or non-string message falls back.
Co-Authored-By: BYK <[email protected]> # Conflicts: # static/packages/api/lib/sentry-errors.ts # static/packages/api/test/error-codes.test.ts
BYK
approved these changes
Nov 16, 2026
jan-auer
added a commit
that referenced
this pull request
Nov 17, 2026
…-store * ref/inline-payload-defaults: (2542 commits) feat(classifiers): Support search syntax in classifier list query (#131423) ref(settings): Update settings tour entry copy (#131424) fix(conversations): Track tab switch from the View Timeline button (#131196) ref(sourcemaps): Read has_debug_ids in the source map debugger (#130425) ci(acceptance): Re-run on the override selective testing label (#131408) feat(inbox): Include inbox URLs in item responses (#131406) ref(flags): Remove `organizations:jira-explicit-mapping-removals` (frontend) (#130393) ci(acceptance): Select acceptance tests on pull requests (#131325) fix(audit-log): Render legacy internal integration token entries (#131042) ref(api): Drop the isRecord guard from SentryApiError body reads (#131394) ref: bump sentry-protos to 0.120.1 (#131396) feat(inbox): add URL configuration for inbox events (#131336) fix(circuit-breaker): Don't raise from record_error or record_success when redis fails (#131364) fix(redis): Let cluster client_args set the per-node connection limit (#131355) fix(sentry-apps): Stop retrying service hooks to blocked or unreachable URLs (#131171) fix(charts): Stop tooltip errors when a chart refresh removes series (#131341) perf(crons): Make the check-in timeout index partial (#131376) feat(api): Know per-operation error codes and read top-level codes (#131362) feat(api): Generate error codes and challenge fields from the spec (#131287) feat(apidocs): Mark auth-challenge error codes in the error component (#131346) ... # Conflicts: # src/sentry/conf/server.py # src/sentry/event_manager.py # src/sentry/ingest/consumer/attachment_event.py # src/sentry/ingest/consumer/processors.py # src/sentry/processing/backpressure/topology.py # src/sentry/tasks/store.py # tests/sentry/ingest/ingest_consumer/test_ingest_consumer_kafka.py # tests/sentry/ingest/ingest_consumer/test_ingest_consumer_processing.py # tests/sentry/processing/backpressure/test_checking.py # tests/sentry/processing/backpressure/test_monitoring.py # tests/sentry/tasks/test_post_process.py # tests/sentry/tasks/test_store.py # tests/sentry/tasks/test_symbolication.py
2 tasks done
xb18
pushed a commit
to xb18/sentry
that referenced
this pull request
Nov 22, 2026
…defaults * origin/master: (2542 commits) feat(classifiers): Support search syntax in classifier list query (getsentry#131423) ref(settings): Update settings tour entry copy (getsentry#131424) fix(conversations): Track tab switch from the View Timeline button (getsentry#131196) ref(sourcemaps): Read has_debug_ids in the source map debugger (getsentry#130425) ci(acceptance): Re-run on the override selective testing label (getsentry#131408) feat(inbox): Include inbox URLs in item responses (getsentry#131406) ref(flags): Remove `organizations:jira-explicit-mapping-removals` (frontend) (getsentry#130393) ci(acceptance): Select acceptance tests on pull requests (getsentry#131325) fix(audit-log): Render legacy internal integration token entries (getsentry#131042) ref(api): Drop the isRecord guard from SentryApiError body reads (getsentry#131394) ref: bump sentry-protos to 0.120.1 (getsentry#131396) feat(inbox): add URL configuration for inbox events (getsentry#131336) fix(circuit-breaker): Don't raise from record_error or record_success when redis fails (getsentry#131364) fix(redis): Let cluster client_args set the per-node connection limit (getsentry#131355) fix(sentry-apps): Stop retrying service hooks to blocked or unreachable URLs (getsentry#131171) fix(charts): Stop tooltip errors when a chart refresh removes series (getsentry#131341) perf(crons): Make the check-in timeout index partial (getsentry#131376) feat(api): Know per-operation error codes and read top-level codes (getsentry#131362) feat(api): Generate error codes and challenge fields from the spec (getsentry#131287) feat(apidocs): Mark auth-challenge error codes in the error component (getsentry#131346) ... # Conflicts: # tests/sentry/ingest/ingest_consumer/test_ingest_consumer_processing.py # tests/sentry/tasks/test_reprocessing2.py # tests/sentry/tasks/test_store.py # tests/sentry/tasks/test_symbolication.py
This branch was successfully deployed
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. Merge after #131362, which is already in master.
lib/sentry-errors.tsread error bodies through a localisRecordtype predicate, a guard TypeScript takes on trust.readSentryErrorDetailandreadTopLevelCodenow narrow withtypeof/=== nullandinchecks instead, so the compiler checks each field read.extrais copied withObject.fromEntries(Object.entries(…))so it stays aRecord<string, unknown>without a cast. The fields read exactly as before: a non-object or arrayextrafalls back to{}, and a non-stringmessagefalls back to"".via @BYK.
--
View Session [Sentry]