diff --git a/.changeset/violet-clocks-study.md b/.changeset/violet-clocks-study.md new file mode 100644 index 0000000000..b6a803e4cf --- /dev/null +++ b/.changeset/violet-clocks-study.md @@ -0,0 +1,5 @@ +--- +"medusa-plugin-sendgrid": patch +--- + +feat(medusa-plugin-sendgrid): Add error messages to SendgridService.sendNotification diff --git a/packages/medusa-plugin-sendgrid/src/services/sendgrid.js b/packages/medusa-plugin-sendgrid/src/services/sendgrid.js index d57695a91d..95dca0344f 100644 --- a/packages/medusa-plugin-sendgrid/src/services/sendgrid.js +++ b/packages/medusa-plugin-sendgrid/src/services/sendgrid.js @@ -2,6 +2,7 @@ import SendGrid from "@sendgrid/mail" import { humanizeAmount, zeroDecimalCurrencies } from "medusa-core-utils" import { NotificationService } from "medusa-interfaces" import { IsNull, Not } from "typeorm" +import { MedusaError } from "@medusajs/utils" class SendGridService extends NotificationService { static identifier = "sendgrid" @@ -221,10 +222,14 @@ class SendGridService extends NotificationService { let templateId = this.getTemplateId(event) if (!templateId) { - return false + throw new MedusaError(MedusaError.Types.INVALID_DATA, `Sendgrid service: No template was set for event: ${event}`) } const data = await this.fetchData(event, eventData, attachmentGenerator) + if (!data) { + throw new MedusaError(MedusaError.Types.INVALID_DATA, "Sendgrid service: Invalid event data was received") + } + const attachments = await this.fetchAttachments( event, data, @@ -256,9 +261,10 @@ class SendGridService extends NotificationService { }) } - const status = await SendGrid.send(sendOptions) - .then(() => "sent") - .catch(() => "failed") + let status + await this.transporter_.sendMail(sendOptions) + .then(() => { status = "sent" }) + .catch((error) => { status = "failed"; console.log(error) }) // We don't want heavy docs stored in DB delete sendOptions.attachments