try to fix runtime error and add runtime logs

This commit is contained in:
2026-01-01 18:26:04 +07:00
parent 598fbf9d4a
commit 90f6e840f3
2 changed files with 11 additions and 1 deletions

View File

@@ -44,6 +44,8 @@ export async function POST(req: NextRequest) {
const cf_token = data["cf-turnstile-response"];
console.log(`[${agent}] Verify captcha`);
if (typeof cf_token !== 'string' || !cf_token.trim()) {
return NextResponse.json(
{ error: "Captcha Failed" },
@@ -59,6 +61,8 @@ export async function POST(req: NextRequest) {
{ status: 403 }
);
}
console.log(`[${agent}] Verify rate limit`);
const isRateLimited = await rateLimited(agent);
@@ -76,12 +80,16 @@ export async function POST(req: NextRequest) {
);
}
console.log(`[${agent}] Sending email...`);
try {
const email = data.anon || !data.email ? process.env.SMTP_USER : data.email;
const name = trimTooLong(data.anon || !data.name ? 'Anonymous' : data.name, 20);
await sendEmail(name, email, data.message);
console.log(`[${agent}] Email sended...`);
return NextResponse.json({ status: "ok" });
}
catch (err) {