Skip to content

Commit

Permalink
Reuse the new function
Browse files Browse the repository at this point in the history
  • Loading branch information
dakota002 committed Mar 7, 2025
1 parent 150a008 commit a837681
Showing 1 changed file with 7 additions and 17 deletions.
24 changes: 7 additions & 17 deletions app/lib/email.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {
import chunk from 'lodash/chunk'

import { hostname } from './env.server'
import { getEnvBannerHeaderAndDescription } from './utils'
import { getEnvBannerHeaderAndDescription, maybeThrow } from './utils'

Check warning on line 23 in app/lib/email.server.ts

View check run for this annotation

Codecov / codecov/patch

app/lib/email.server.ts#L23

Added line #L23 was not covered by tests
import { encodeToURL } from '~/routes/unsubscribe.$jwt/jwt.server'

const client = new SESv2Client({})
Expand Down Expand Up @@ -79,24 +79,14 @@ async function send(sendCommandInput: SendEmailCommandInput) {
}
}

function maybeThrow(e: any, warning: string) {
const errorsAllowedInDev = [
function maybeThrowSES(e: any, warning: string) {
const formattedWarning = `SES threw ${(e as SESv2ServiceException).name}. This would be an error in production. Since we are in ${process.env.NODE_ENV}, ${warning}.`

Check warning on line 83 in app/lib/email.server.ts

View check run for this annotation

Codecov / codecov/patch

app/lib/email.server.ts#L82-L83

Added lines #L82 - L83 were not covered by tests

maybeThrow<SESv2ServiceException>(e, formattedWarning, [

Check warning on line 85 in app/lib/email.server.ts

View check run for this annotation

Codecov / codecov/patch

app/lib/email.server.ts#L85

Added line #L85 was not covered by tests
'ExpiredTokenException',
'NotAuthorizedException',
'UnrecognizedClientException',
]
const { name } = e as SESv2ServiceException

if (
!errorsAllowedInDev.includes(name) ||
process.env.NODE_ENV === 'production'
) {
throw e
} else {
console.warn(
`SES threw ${name}. This would be an error in production. Since we are in ${process.env.NODE_ENV}, ${warning}.`
)
}
])
}

/** Send an email to many recipients in parallel. */
Expand Down Expand Up @@ -143,7 +133,7 @@ export async function sendEmailBulk({
new SendBulkEmailCommand({ BulkEmailEntries, ...message })
)
} catch (e) {
maybeThrow(e, 'email will not be sent')
maybeThrowSES(e, 'email will not be sent')

Check warning on line 136 in app/lib/email.server.ts

View check run for this annotation

Codecov / codecov/patch

app/lib/email.server.ts#L136

Added line #L136 was not covered by tests
}
})
)
Expand Down

0 comments on commit a837681

Please sign in to comment.