Skip to content

fix(api): 1392 send email to each recipient as separate requests#1595

Open
JazzarKarim wants to merge 7 commits intobcgov:mainfrom
JazzarKarim:1392-send-email-seperate
Open

fix(api): 1392 send email to each recipient as separate requests#1595
JazzarKarim wants to merge 7 commits intobcgov:mainfrom
JazzarKarim:1392-send-email-seperate

Conversation

@JazzarKarim
Copy link
Copy Markdown
Collaborator

@JazzarKarim JazzarKarim commented Apr 29, 2026

Issue:

Description of changes:

  • Updated STRR email delivery so each recipient is sent as a separate notify-api request
    • Now, valid recipients still receive their email even if one or more recipients are invalid
  • Added tests

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of the BC Registry and Digital Services BSD 3-Clause License

@JazzarKarim JazzarKarim self-assigned this Apr 29, 2026
@JazzarKarim JazzarKarim force-pushed the 1392-send-email-seperate branch from 413602d to b3baba6 Compare April 29, 2026 20:48
@JazzarKarim JazzarKarim marked this pull request as ready for review April 29, 2026 21:39
last_failure_status = None
for recipient in recipients_list:
single_email = {**email, "recipients": recipient}
resp = requests.post(
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This api call could results in errors that could lead to 5xx errors. is that intended?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually Jimmy, good point. I've changed this to a return an HTTP 400 (Bad Request) if sending to particular recipient fails. I think that would be more accurate and makes more sense.

I've also added some logging to indicate which recipient it was.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i am not sure about 400 as that would imply user error. I wouldnt do that unless we are absolutely sure that the error results from bad email (which would be a user error). what do you think?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking that the error does indeed stem from a user error right? Since the email was poorly formatted (input was something wrong), like @ba$.com which is invalid. The sending of email fails in this case. That's why I was thinking in this a 4xx makes sense? Thoughts?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The try catch logic will catch any excpetion and throw 4xx. I am not sure if thats the right behaviour

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, good point, thanks. Fixed.

Now, if the error is from the recipient's email being badly formatted, it's a 400 error.
Otherwise, it's a 502 error (Bad Gateway).

This should make the error message not to be misleading.

interaction.customer_id = customer_id
interaction.user_id = user_id
interaction.notify_reference = notify_id
interaction.notify_reference = notify_json.get("ids") or notify_id
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sanity check: we are modifying the shape of the notify_reference here. is this clear of any downstream side effects?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed this to make it backwards compatible as a single notify ID again. That should be much safer. Thanks Jimmy.

@sonarqubecloud
Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants