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:
co-authored by
Oliver Windall Juhl
parent
c71161cfe5
commit
f65a501da5
@@ -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 { humanizeAmount, zeroDecimalCurrencies } from "medusa-core-utils"
|
||||||
import { NotificationService } from "medusa-interfaces"
|
import { NotificationService } from "medusa-interfaces"
|
||||||
import { IsNull, Not } from "typeorm"
|
import { IsNull, Not } from "typeorm"
|
||||||
|
import { MedusaError } from "@medusajs/utils"
|
||||||
|
|
||||||
class SendGridService extends NotificationService {
|
class SendGridService extends NotificationService {
|
||||||
static identifier = "sendgrid"
|
static identifier = "sendgrid"
|
||||||
@@ -221,10 +222,14 @@ class SendGridService extends NotificationService {
|
|||||||
let templateId = this.getTemplateId(event)
|
let templateId = this.getTemplateId(event)
|
||||||
|
|
||||||
if (!templateId) {
|
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)
|
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(
|
const attachments = await this.fetchAttachments(
|
||||||
event,
|
event,
|
||||||
data,
|
data,
|
||||||
@@ -256,9 +261,10 @@ class SendGridService extends NotificationService {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
const status = await SendGrid.send(sendOptions)
|
let status
|
||||||
.then(() => "sent")
|
await this.transporter_.sendMail(sendOptions)
|
||||||
.catch(() => "failed")
|
.then(() => { status = "sent" })
|
||||||
|
.catch((error) => { status = "failed"; console.log(error) })
|
||||||
|
|
||||||
// We don't want heavy docs stored in DB
|
// We don't want heavy docs stored in DB
|
||||||
delete sendOptions.attachments
|
delete sendOptions.attachments
|
||||||
|
|||||||
Reference in New Issue
Block a user