fix: add logging and genericize error responses in domains handler#53
fix: add logging and genericize error responses in domains handler#53SatishKumar620 wants to merge 2 commits intoOWASP-BLT:mainfrom
Conversation
- Add logging import and logger instance - Log full exception details server-side via logger.error() - Return generic messages to clients instead of raw str(e) - Consistent with pattern applied in organizations handler (PR OWASP-BLT#50) Closes OWASP-BLT#52
📊 Monthly LeaderboardHi @SatishKumar620! Here's how you rank for March 2026:
Scoring this month (across OWASP-BLT org): Open PRs (+1 each), Merged PRs (+10), Closed (not merged) (−2), Reviews (+5; first two per PR in-month), Comments (+2, excludes CodeRabbit). Run |
|
👋 Hi @SatishKumar620! This pull request needs a peer review before it can be merged. Please request a review from a team member who is not:
Once a valid peer review is submitted, this check will pass automatically. Thank you!
|
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository: OWASP-BLT/coderabbit/.coderabbit.yml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
WalkthroughIntroduced a module-level logger in Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Suggested labels
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
📝 Coding Plan
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 |
There was a problem hiding this comment.
Actionable comments posted: 4
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@src/handlers/domains.py`:
- Around line 86-87: The logger call in the exception handler for fetching
domain tags (the logger.error call that currently logs f"Failed to fetch domain
tags: {str(e)}") should be updated to include full traceback by passing
exc_info=True; locate the exception block in the function that returns
error_response("Failed to fetch domain tags", status=500) and change the
logger.error invocation to include exc_info=True so the stack trace is recorded
alongside the error message.
- Around line 125-126: In the exception handler in src/handlers/domains.py (the
line calling logger.error(f"Failed to fetch domains: {str(e)}") before returning
error_response("Failed to fetch domains", status=500)), include the full
traceback by passing exc_info=True to logger.error so the log contains stack
trace information; keep the existing message and return behavior the same.
- Around line 98-99: The error log in src/handlers/domains.py currently calls
logger.error(f"Failed to fetch domain: {str(e)}") without the traceback; update
that logger.error invocation to include exc_info=True (e.g.,
logger.error("Failed to fetch domain", exc_info=True)) so the full traceback is
captured in the logs while keeping the existing error_response("Failed to fetch
domain", status=500) behavior intact.
- Around line 44-45: Replace the current single-line exception log so it
includes the full traceback and uses Ruff-recommended formatting: change the
logger.error call that currently formats the exception with str(e) (the
logger.error in this block) to include exc_info=True and use {e!s} for the
message, or use logger.exception(...) instead; keep the subsequent return
error_response("Database connection failed", status=503) intact. This ensures
the database connection error logs the full stack trace while preserving the
existing error response flow.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository: OWASP-BLT/coderabbit/.coderabbit.yml
Review profile: CHILL
Plan: Pro
Run ID: 06a45f94-42e6-4abf-b81b-65bd634dc218
📒 Files selected for processing (1)
src/handlers/domains.py
- Add exc_info=True to capture full stack traces for debugging - Replace str(e) with e!s per Ruff RUF010 recommendation
|
@coderabbitai Please assess the PR's completeness and merge readiness within scope. |
|
Tip For best results, initiate chat on the files or code changes. 🧩 Analysis chain🏁 Script executed: Length of output: 2086 🏁 Script executed: Length of output: 16960
✅ Completeness & Merge ReadinessScope: Issue
CI: Passing ✅
|
Kunal241207
left a comment
There was a problem hiding this comment.
Nice improvement
One small suggestion: you might consider using logger.exception("message") instead of f-string logging with exc_info=True for slightly cleaner stacktrace handling and more consistent logging style.
|
@Kunal241207 sure |
arnavkirti
left a comment
There was a problem hiding this comment.
A couple of minor suggestions:
- If the project uses a shared logger helper, it might be good to reuse that here instead of creating a module-level logger directly.
- It could be worth adding tests to ensure we don’t regress and accidentally return raw exception messages again, and to verify the status codes and response schema.
Overall, looks good to me after addressing the minor points.
|
@arnavkirti sure |



Problem
In
src/handlers/domains.py, all four error responses exposed rawexception details to clients via str(e), and there was no logging
at all making production debugging impossible:
Fix
Closes #52
Summary by CodeRabbit