diff --git a/.changeset/strong-wasps-judge.md b/.changeset/strong-wasps-judge.md new file mode 100644 index 00000000..d3953315 --- /dev/null +++ b/.changeset/strong-wasps-judge.md @@ -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. diff --git a/packages/api/src/brevo-api/brevo-api-contact.service.ts b/packages/api/src/brevo-api/brevo-api-contact.service.ts index 3788ce3c..2d6480f8 100644 --- a/packages/api/src/brevo-api/brevo-api-contact.service.ts +++ b/packages/api/src/brevo-api/brevo-api-contact.service.ts @@ -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;