Repository navigation
Mail issues #256
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Mail issues #256
Changes from all commits
67cd9e2
7730073
868e7b5
e1ca1eb
d7e75d9
3452da4
efcc655
6c63cdb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -26,21 +26,27 @@ const createAnswer = async (req, res) => { | |
| question.answers.push(answer); | ||
| await question.save(); | ||
|
|
||
| // Send email notification to the person who asked the question | ||
| if (question.askedBy.personalEmail && question.askedBy._id.toString() !== author) { | ||
| const answeredBy = await User.findById(author); | ||
| const emailContent = newAnswerTemplate( | ||
| question.askedBy, | ||
| question.postId.title, | ||
| question.question, | ||
| content, | ||
| answeredBy, | ||
| question.postId._id | ||
| ); | ||
| await sendEmail({ | ||
| to: question.askedBy.personalEmail, | ||
| ...emailContent | ||
| }); | ||
| // Send email notification to the person who asked the question (non-blocking) | ||
| try { | ||
| const recipient = question?.askedBy?.personalEmail || question?.askedBy?.instituteEmail; | ||
| if (recipient && question.askedBy._id.toString() !== author) { | ||
| const answeredBy = await User.findById(author); | ||
| const emailContent = newAnswerTemplate( | ||
| question.askedBy, | ||
| question.postId.title, | ||
| question.question, | ||
| content, | ||
| answeredBy, | ||
| question.postId._id | ||
| ); | ||
| await sendEmail({ | ||
| to: recipient, | ||
| ...emailContent, | ||
| critical: false | ||
| }); | ||
| } | ||
| } catch (emailErr) { | ||
| console.error("Non-blocking error sending answer notification email:", emailErr); | ||
| } | ||
|
|
||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This change improves reliability by ensuring answer notifications do not block the answer creation flow if email delivery fails. The fallback to instituteEmail and non-blocking error handling are sensible, and they reduce user-facing disruption without changing the main business logic. |
||
| // Populate the author details of the new answer | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This patch improves the create-post flow by handling unauthenticated users before the request is sent and by gracefully handling expired sessions with a clearer message and redirect. The error handling is more user-friendly and avoids leaving stale auth state behind. No blockers from this diff