Skip to content

Commit

Permalink
fix: handle blacklisted recipient in SST (#2132)
Browse files Browse the repository at this point in the history
* fix: handle blacklisted recipient

* refactor: no need
  • Loading branch information
zxt-tzx authored Jul 28, 2023
1 parent 33095b4 commit 853acb3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
11 changes: 10 additions & 1 deletion sst/packages/core/src/util/email.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// to replace with fetch when upgraded to Node 18
import axios from 'axios'
import axios, { AxiosError } from 'axios'
import { Config } from 'sst/node/config'

const SST_STAGE = process.env.SST_STAGE
Expand All @@ -25,6 +25,15 @@ export const sendEmail = async (email: Email) => {
},
})
.catch((err) => {
if (err instanceof AxiosError && err.response?.status === 400) {
const { message } = err.response.data
if (message === 'Recipient email is blacklisted') {
console.log(
`Recipient email ${email.recipient} is blacklisted, skipping`,
)
return
}
}
console.error(err)
throw err
})
Expand Down
4 changes: 0 additions & 4 deletions sst/stacks/MyStack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@ export function MyStack({ app, stack }: StackContext) {
const postmanDbUri = new Config.Secret(stack, 'POSTMAN_DB_URI')
const postmanApiKey = new Config.Secret(stack, 'POSTMAN_API_KEY')
const cronitorUrlSuffix = new Config.Secret(stack, 'CRONITOR_URL_SUFFIX')
app.addDefaultFunctionEnv({
SST_STAGE: app.stage,
})

const { vpcName, lookupOptions, sgName, sgId } = getResourceIdentifiers(
app.stage,
)
Expand Down

0 comments on commit 853acb3

Please sign in to comment.