Skip to content

Commit

Permalink
chore: replace wretch with native fetch (#385)
Browse files Browse the repository at this point in the history
* chore: replace wretch with native fetch

* feat: add status text to error message
  • Loading branch information
zhongliang02 authored Jan 3, 2025
1 parent 17f952a commit 96c8c6f
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 20 deletions.
14 changes: 0 additions & 14 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@
"type-fest": "^4.26.1",
"usehooks-ts": "^2.9.2",
"validator": "^13.11.0",
"wretch": "^2.8.0",
"zod": "^3.22.4"
},
"devDependencies": {
Expand Down
22 changes: 17 additions & 5 deletions src/lib/mail.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import sendgrid from '@sendgrid/mail'
import wretch from 'wretch'

import { env } from '~/env.mjs'

Expand All @@ -17,12 +16,25 @@ export const sgClient = env.SENDGRID_API_KEY ? sendgrid : null

export const sendMail = async (params: SendMailParams): Promise<void> => {
if (env.POSTMAN_API_KEY) {
return await wretch(
const response = await fetch(
'https://api.postman.gov.sg/v1/transactional/email/send',
{
method: 'POST',
headers: {
Authorization: `Bearer ${env.POSTMAN_API_KEY}`,
'Content-Type': 'application/json',
},
body: JSON.stringify(params),
},
)
.auth(`Bearer ${env.POSTMAN_API_KEY}`)
.post(params)
.res()

if (!response.ok) {
throw new Error(
`HTTP error! status: ${response.status} ${response.statusText}`,
)
}

return
}

if (sgClient && env.SENDGRID_FROM_ADDRESS) {
Expand Down

1 comment on commit 96c8c6f

@vercel
Copy link

@vercel vercel bot commented on 96c8c6f Jan 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.