mirror of
https://github.com/tomru/pfadi-bussle.git
synced 2026-03-03 06:27:11 +01:00
add retry for sending mail *sigh*
This commit is contained in:
@@ -2,6 +2,7 @@ import { Booking } from '../db/booking'
|
||||
import { getBaseURL } from '../helpers/url'
|
||||
import { daysFormatFrontend } from './date'
|
||||
import { generateCalendarEntry } from './ical'
|
||||
import { retryWithDelay } from './retryWithDelay'
|
||||
|
||||
const SENDGRID_API_KEY = process.env.SENDGRID_API_KEY
|
||||
const ADMIN_EMAIL = process.env.ADMIN_EMAIL
|
||||
@@ -195,12 +196,17 @@ async function sendMail({
|
||||
},
|
||||
body: JSON.stringify(data),
|
||||
}
|
||||
const resp = await fetch(SENDGRID_URL, fetchOptions)
|
||||
const bodyText = await resp.text()
|
||||
|
||||
if (!resp.ok) {
|
||||
throw new Error(
|
||||
`Unable to send mail, status ${resp.status} ${resp.statusText}, ${bodyText}`
|
||||
)
|
||||
}
|
||||
return retryWithDelay({
|
||||
run: async () => {
|
||||
const resp = await fetch(SENDGRID_URL, fetchOptions)
|
||||
const bodyText = await resp.text()
|
||||
|
||||
if (!resp.ok) {
|
||||
throw new Error(
|
||||
`Failed to send mail with status ${resp.status}: ${bodyText}`
|
||||
)
|
||||
}
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user