-
-
Notifications
You must be signed in to change notification settings - Fork 772
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
34 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,47 +17,50 @@ export const earlyAccessRouter = createRouter({ | |
const { email, name, reason } = input; | ||
const { db, resend } = ctx; | ||
|
||
try { | ||
await db.insert(earlyAccessTable).values({ | ||
await db | ||
.insert(earlyAccessTable) | ||
.values({ | ||
email, | ||
name, | ||
reason, | ||
}); | ||
}) | ||
.catch((err: unknown) => { | ||
if (err instanceof Error) { | ||
if ( | ||
err.message.includes( | ||
'duplicate key value violates unique constraint', | ||
) | ||
) { | ||
throw new TRPCError({ | ||
code: 'BAD_REQUEST', | ||
cause: err, | ||
message: 'This email is already on the early access list.', | ||
}); | ||
} | ||
|
||
await resend.emails.send({ | ||
from: 'Noodle <[email protected]>', | ||
to: email, | ||
subject: "You are on Noodle's early access list!", | ||
react: EarlyAccessJoinedEmail({ name, email }), | ||
}); | ||
} catch (err) { | ||
if (err instanceof Error) { | ||
if ( | ||
err.message.includes( | ||
'duplicate key value violates unique constraint', | ||
) | ||
) { | ||
throw new TRPCError({ | ||
code: 'BAD_REQUEST', | ||
code: 'INTERNAL_SERVER_ERROR', | ||
cause: err, | ||
message: 'This email is already on the early access list.', | ||
message: | ||
'An error occurred while adding you to the early access list. Please try again later.', | ||
}); | ||
} | ||
}); | ||
|
||
await resend.emails | ||
.send({ | ||
from: 'Noodle <[email protected]>', | ||
to: email, | ||
subject: "You are on Noodle's early access list!", | ||
react: EarlyAccessJoinedEmail({ name, email }), | ||
}) | ||
.catch((err: unknown) => { | ||
throw new TRPCError({ | ||
code: 'INTERNAL_SERVER_ERROR', | ||
cause: err, | ||
message: | ||
'An error occurred while adding you to the early access list. Please try again later.', | ||
}); | ||
} | ||
|
||
throw new TRPCError({ | ||
code: 'INTERNAL_SERVER_ERROR', | ||
cause: err, | ||
message: | ||
'An error occurred while adding you to the early access list. Please try again later.', | ||
}); | ||
} | ||
}), | ||
}); |