Skip to content

Commit

Permalink
Return null instead of undefined
Browse files Browse the repository at this point in the history
  • Loading branch information
RainbowBunchie committed Oct 11, 2024
1 parent bdffcee commit 44f4fbb
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions packages/api/src/brevo-api/brevo-api-contact.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ export class BrevoApiContactsService {
}
}

public async findContact(idOrEmail: string | number, scope: EmailCampaignScopeInterface): Promise<BrevoContactInterface | undefined> {
public async findContact(idOrEmail: string | number, scope: EmailCampaignScopeInterface): Promise<BrevoContactInterface | null> {
try {
const idAsString = String(idOrEmail); // brevo expects a string, because it can be an email or the id
const { body } = await this.getContactsApi(scope).getContactInfo(idAsString);
Expand All @@ -117,23 +117,23 @@ export class BrevoApiContactsService {
} catch (error) {
// 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;
return null;
}

handleBrevoError(error);
}
}

public async getContactInfoByEmail(email: string, scope: EmailCampaignScopeInterface): Promise<BrevoContactInterface | undefined> {
public async getContactInfoByEmail(email: string, scope: EmailCampaignScopeInterface): Promise<BrevoContactInterface | null> {
try {
const data = await this.getContactsApi(scope).getContactInfo(email);
const contact = data.body;
if (!contact) return undefined;
if (!contact) return null;
return contact;
} catch (error) {
// 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;
return null;
}
handleBrevoError(error);
}
Expand Down

0 comments on commit 44f4fbb

Please sign in to comment.