feat(medusa-plugin-sendgrid): Add error messages (#4384)
* add error messages to SendgridService.sendNotification * add event name to msg for no template set for event * Create violet-clocks-study.md --------- Co-authored-by: Oliver Windall Juhl <59018053+olivermrbl@users.noreply.github.com>
This commit is contained in:
5
.changeset/violet-clocks-study.md
Normal file
5
.changeset/violet-clocks-study.md
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"medusa-plugin-sendgrid": patch
|
||||
---
|
||||
|
||||
feat(medusa-plugin-sendgrid): Add error messages to SendgridService.sendNotification
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user