fix(api): add HTTPException handler for observability#2542
Merged
daryllimyt merged 2 commits intomainfrom Apr 20, 2026
Merged
Conversation
Add custom exception handler for HTTPException that logs 4xx/5xx errors with tenant context (role, workspace_id, org_id). This improves observability for API errors that were previously only visible in HTTP access logs without details. - Use logger.warning for 4xx, logger.error for 5xx - Include role context, path, method, status_code, and detail
|
✅ No security or compliance issues detected. Reviewed everything up to 5bb40bb. Security OverviewDetected Code Changes
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: f97d556d81
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Contributor
|
Found 1 test failure on Blacksmith runners: Failure
|
Contributor
There was a problem hiding this comment.
2 issues found across 2 files
Confidence score: 2/5
- There is a high-confidence, user-facing regression risk in
tracecat/api/app.py: the global customHTTPExceptionhandler changes FastAPI semantics by dropping exception headers and always returning a body, which can break auth challenges and HTTP no-body status behavior. - The issue in
tracecat/api/common.pyis similarly severe (7/10, confidence 9/10): missing propagation ofHTTPExceptionheaders can strip critical protocol headers likeWWW-AuthenticateandRetry-After, impacting auth and rate-limit flows. - Given both findings are concrete and protocol-impacting rather than cosmetic, this is higher merge risk until header propagation and response-shape compatibility are corrected.
- Pay close attention to
tracecat/api/app.pyandtracecat/api/common.py- custom exception handling must preserve FastAPI/HTTP header and body semantics.
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="tracecat/api/app.py">
<violation number="1" location="tracecat/api/app.py:583">
P1: Registering the custom HTTPException handler globally changes FastAPI’s response semantics: it drops exception headers and always returns a body, which can break auth challenges and HTTP compliance for no-body status codes.</violation>
</file>
<file name="tracecat/api/common.py">
<violation number="1" location="tracecat/api/common.py:45">
P1: Propagate `HTTPException` headers in the custom handler; otherwise auth/rate-limit semantics can break (e.g., missing `WWW-Authenticate` or `Retry-After`).</violation>
</file>
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.
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.
Summary
HTTPExceptionthat logs 4xx/5xx errors with tenant contextlogger.warningfor 4xx,logger.errorfor 5xxContext
When investigating customer issues (e.g., git sync 400 errors), we could only see HTTP access logs like:
The actual error detail (e.g., "Git repository URL not configured") was returned to the client but not logged server-side.
Test plan
Summary by cubic
Add a custom FastAPI
HTTPExceptionhandler that logs 4xx as warnings and 5xx as errors with tenant role context and request info, and delegates response formatting to FastAPI’s default handler. Registered globally so API errors are logged with path, method, status, and detail while clients receive the standard JSON response.Written for commit 5bb40bb. Summary will update on new commits.