add retry for sending mail *sigh*

This commit is contained in:
Thomas Ruoff
2020-11-11 23:24:43 +01:00
parent 7630f56b70
commit 460510e52b
4 changed files with 53 additions and 7 deletions

View File

@@ -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}`
)
}
},
})
}