Skip to content

Commit

Permalink
Catch contact search errors from brevo api (#94)
Browse files Browse the repository at this point in the history
Co-authored-by: thomashuettmaier <[email protected]>
  • Loading branch information
thomashuettmaier and thomashuettmaier authored Sep 16, 2024
1 parent 8872783 commit 3606421
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/strong-wasps-judge.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@comet/brevo-api": minor
---

Brevo returns a 404 error when an email address is not found and a 400 error if an invalid email is provided. Instead of handling only one of these errors, both status codes must be ignored to prevent the contact search from throwing an error.
4 changes: 2 additions & 2 deletions packages/api/src/brevo-api/brevo-api-contact.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ export class BrevoApiContactsService {
if (!contact) return undefined;
return contact;
} catch (error) {
// Brevo throws 404 error if no contact was found
if (isErrorFromBrevo(error) && error.response.statusCode === 404) {
// Brevo returns a 404 error if no contact is found and a 400 error if an invalid email is provided.
if (isErrorFromBrevo(error) && (error.response.statusCode === 404 || error.response.statusCode === 400)) {
return undefined;
}
throw error;
Expand Down

0 comments on commit 3606421

Please sign in to comment.