added exception handling and raising error for failed emails#3531
added exception handling and raising error for failed emails#3531
Conversation
📝 WalkthroughWalkthroughMoves email-sending error handling from the utility into the view: the email utility no longer swallows exceptions, the reset-password view now catches send failures and returns HTTP 503, and a test was added asserting 503 on email-send exceptions. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~22 minutes 🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
No actionable comments were generated in the recent review. 🎉 🧹 Recent nitpick comments
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
care/users/reset_password_views.py (1)
149-188:⚠️ Potential issue | 🟠 MajorReturn a structured
ResetPasswordResponse(and document 503) for the new failure path.Right now the 503 returns a bare string and the schema doesn’t mention 503. That’s a quiet contract change for clients. Please keep the response shape consistent and update the schema.
Proposed fix
responses={ + 503: ResetPasswordResponse, }, @@ - except Exception: - return Response( - "Failed to send password reset email. Please try again.", - status=status.HTTP_503_SERVICE_UNAVAILABLE, - ) + except Exception: + error_message = "Failed to send password reset email. Please try again." + response = ResetPasswordResponse(detail=error_message).model_dump() + return Response( + response, + status=status.HTTP_503_SERVICE_UNAVAILABLE, + )
🤖 Fix all issues with AI agents
In `@care/users/reset_password_views.py`:
- Around line 182-188: Replace the blanket except Exception around the
send_password_reset_email call with explicit except clauses for email-related
failures (e.g., django.core.mail.BadHeaderError, smtplib.SMTPException) and
network errors (OSError, TimeoutError); for each caught exception log the
exception details (using the module logger or existing logging facility) and
then return the same 503 Response so unrelated bugs still surface, keeping the
try/except only around send_password_reset_email in the reset password view.
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@care/users/reset_password_views.py`:
- Around line 182-190: The except block that catches exceptions from
send_password_reset_email currently returns a raw dict response; change it to
construct and return a ResetPasswordResponse(detail="Failed to send password
reset email. Please try again.").model_dump() with
status=status.HTTP_503_SERVICE_UNAVAILABLE so it matches the other error
responses in this file (same pattern used at lines referencing
ResetPasswordResponse elsewhere) and is returned from the except handling around
send_password_reset_email.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## develop #3531 +/- ##
========================================
Coverage 75.45% 75.45%
========================================
Files 473 473
Lines 21977 21972 -5
Branches 2293 2293
========================================
- Hits 16582 16579 -3
+ Misses 4877 4875 -2
Partials 518 518 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
…set-password-mail
Proposed Changes
Associated Issue
Architecture changes
Merge Checklist
/docsOnly PR's with test cases included and passing lint and test pipelines will be reviewed
@ohcnetwork/care-backend-maintainers @ohcnetwork/care-backend-admins
Summary by CodeRabbit
Bug Fixes
Tests
Documentation