1
mirror of https://github.com/jakejarvis/jarv.is.git synced 2026-06-05 19:15:30 -04:00

Refactor bot detection logic in contact form to improve error handling. Log verification failures and throw errors for better debugging.

This commit is contained in:
2025-09-03 11:05:24 -04:00
parent 9db5c142e5
commit a3f05dc7d8
3 changed files with 139 additions and 138 deletions
+10 -9
View File
@@ -16,15 +16,16 @@ export type ContactState = {
export const send = async (state: ContactState, payload: FormData): Promise<ContactState> => {
// TODO: remove after debugging why automated spam entries are causing 500 errors
console.debug("[server/resend] received payload:", payload);
console.debug("[server/contact] received payload:", payload);
// BotID server-side verification
const verification = await checkBotId();
if (verification.isBot) {
console.warn("[server/contact] botid verification failed:", verification);
throw new Error("Bot check failed");
}
try {
// BotID server-side verification
const verification = await checkBotId();
if (verification.isBot) {
return { success: false, message: "Bot detection failed. 🤖" };
}
const data = ContactSchema.safeParse(Object.fromEntries(payload));
if (!data.success) {
@@ -37,7 +38,7 @@ export const send = async (state: ContactState, payload: FormData): Promise<Cont
if (env.RESEND_FROM_EMAIL === "onboarding@resend.dev") {
// https://resend.com/docs/api-reference/emails/send-email
console.warn("[server/resend] 'RESEND_FROM_EMAIL' is not set, falling back to onboarding@resend.dev.");
console.warn("[server/contact] 'RESEND_FROM_EMAIL' is not set, falling back to onboarding@resend.dev.");
}
// send email
@@ -52,7 +53,7 @@ export const send = async (state: ContactState, payload: FormData): Promise<Cont
return { success: true, message: "Thanks! You should hear from me soon." };
} catch (error) {
console.error("[server/resend] fatal error:", error);
console.error("[server/contact] fatal error:", error);
return {
success: false,