Check if the env is local

This commit is contained in:
Hongbo Wu 2023-01-06 15:28:45 +08:00
parent d86a6038ea
commit 9762b14ebc

View file

@ -1,5 +1,6 @@
import { MailService } from '@sendgrid/mail'
import { MailDataRequired } from '@sendgrid/helpers/classes/mail'
import { env } from '../env'
type SendGridResponse = {
body?: string
@ -23,8 +24,12 @@ const asSendGridError = (error: any): SendGridError | undefined => {
export const sendEmail = async (msg: MailDataRequired): Promise<boolean> => {
const client = new MailService()
if (!process.env.SENDGRID_MSGS_API_KEY) {
console.log('SendGrid API key not set.\nSending email:', msg)
return true
if (env.dev.isLocal) {
console.log('SendGrid API key not set.\nSending email:', msg)
return true
}
throw 'SendGrid API key not set'
}
client.setApiKey(process.env.SENDGRID_MSGS_API_KEY)