Code seems to stop execution

Im trying to send an email using resend. Locally, the email sends just fine, but when I host it on Vercel, it looks like the function stops execution. One moment the code is running spitting out logs and then it goes silent. It stops right when i get to the call to send the email. I don't see any timeouts so im confused as to why it fails. It is kind of strange the way I call the function and that is the only thing i can think. Its a server action that calls a server side trpc query. That query fires off a chain of functions that should result in an email.
'use server'
import { ClientVerification, AgentMeetingApproval, ClientConfirmation } from "../_components/emailTemplates";
import { verifyClientToken, verifyAgentToken, createAgentToken } from "../_actions/tokens";
import { Resend } from "resend";
import type { emailPayload, email } from "../_types/types";

export async function sendClientVerification(payload: emailPayload) {
console.log("Building client verification email");
const email = {
from: payload.from,
to: payload.to,
subject: payload.subject,
react: ClientVerification({
fullName: payload.props.fullName,
phoneNumber: payload.props.phoneNumber,
dateString: payload.props.dateString,
jwtTokenEncoded: payload.props.token,
}),
text: payload.text,
} as email;
console.log(email);
try {
const data = await sendEmail(email);
console.log("email data", data);
return true;
} catch (error) {
console.log(error);
}
}

async function sendEmail(email: email): Promise<Response> {
console.log("Sending Email Started");
const NEXT_RESEND_API_KEY = getResendAPIKey();
const resend = createResend(NEXT_RESEND_API_KEY);
const response = await send(resend, email)
console.log(response);
return response
}

function createResend(NEXT_RESEND_API_KEY: string): Resend {
try {
const resend = new Resend(NEXT_RESEND_API_KEY);
console.log(`Created resend object`);
return resend;
} catch (error) {
console.log(error);
throw new Error("Failed to create Resend object");
}
}

function getResendAPIKey(): string {
const { NEXT_RESEND_API_KEY } = process.env;
console.log(`Getting resend key ${NEXT_RESEND_API_KEY}`);
if (!NEXT_RESEND_API_KEY) {
console.log("No API Token");
throw new ReferenceError("Resend API key is not set");
}
return NEXT_RESEND_API_KEY;
}

async function send(resend: Resend, email: email): Promise<Response> {
try {
console.log("trying to send the email");
const data = await resend.emails.send(email);
return Response.json({data});
} catch (error) {
console.log(error);
throw new Error("Could not send email");
}
}
'use server'
import { ClientVerification, AgentMeetingApproval, ClientConfirmation } from "../_components/emailTemplates";
import { verifyClientToken, verifyAgentToken, createAgentToken } from "../_actions/tokens";
import { Resend } from "resend";
import type { emailPayload, email } from "../_types/types";

export async function sendClientVerification(payload: emailPayload) {
console.log("Building client verification email");
const email = {
from: payload.from,
to: payload.to,
subject: payload.subject,
react: ClientVerification({
fullName: payload.props.fullName,
phoneNumber: payload.props.phoneNumber,
dateString: payload.props.dateString,
jwtTokenEncoded: payload.props.token,
}),
text: payload.text,
} as email;
console.log(email);
try {
const data = await sendEmail(email);
console.log("email data", data);
return true;
} catch (error) {
console.log(error);
}
}

async function sendEmail(email: email): Promise<Response> {
console.log("Sending Email Started");
const NEXT_RESEND_API_KEY = getResendAPIKey();
const resend = createResend(NEXT_RESEND_API_KEY);
const response = await send(resend, email)
console.log(response);
return response
}

function createResend(NEXT_RESEND_API_KEY: string): Resend {
try {
const resend = new Resend(NEXT_RESEND_API_KEY);
console.log(`Created resend object`);
return resend;
} catch (error) {
console.log(error);
throw new Error("Failed to create Resend object");
}
}

function getResendAPIKey(): string {
const { NEXT_RESEND_API_KEY } = process.env;
console.log(`Getting resend key ${NEXT_RESEND_API_KEY}`);
if (!NEXT_RESEND_API_KEY) {
console.log("No API Token");
throw new ReferenceError("Resend API key is not set");
}
return NEXT_RESEND_API_KEY;
}

async function send(resend: Resend, email: email): Promise<Response> {
try {
console.log("trying to send the email");
const data = await resend.emails.send(email);
return Response.json({data});
} catch (error) {
console.log(error);
throw new Error("Could not send email");
}
}
In trpc land
sendClientVerification: publicProcedure
.input(jwtPayloadSchema)
.query(async ({ input }) => {
console.log("TRPC CALL");
const token = await createClientToken(input);
const email = {
from: "Website Assistant <[email protected]>",
subject: "Orlando Homes Verify Email",
props: {
fullName: input.fullName,
email: input.email,
phoneNumber: input.phoneNumber,
token: token,
dateString: input.dateString,
},
text: "Please help verify your email",
} as emailPayload;

const data = await sendClientVerification(email).catch((error) => {
console.log(error);
});
console.log(data);
return true
}),
sendClientVerification: publicProcedure
.input(jwtPayloadSchema)
.query(async ({ input }) => {
console.log("TRPC CALL");
const token = await createClientToken(input);
const email = {
from: "Website Assistant <[email protected]>",
subject: "Orlando Homes Verify Email",
props: {
fullName: input.fullName,
email: input.email,
phoneNumber: input.phoneNumber,
token: token,
dateString: input.dateString,
},
text: "Please help verify your email",
} as emailPayload;

const data = await sendClientVerification(email).catch((error) => {
console.log(error);
});
console.log(data);
return true
}),
And i start the chain with
export async function sendClientVerificationApi(tokenPayload: jwtPayload) {
api.emails.sendClientVerification(tokenPayload).catch((error) => {
console.log(error);
});
console.log("sending");
export async function sendClientVerificationApi(tokenPayload: jwtPayload) {
api.emails.sendClientVerification(tokenPayload).catch((error) => {
console.log(error);
});
console.log("sending");
1 Reply
ideceddy
ideceddy6mo ago
16 hr of debugging and it was a missing await. The Vercel edge function would just stop executing after 10 seconds because it got no indication that it was waiting on a promise.
export async function sendClientVerificationApi(tokenPayload: jwtPayload) {
await api.emails.sendClientVerification(tokenPayload).catch((error) => {
console.log(error);
});
console.log("sending");
export async function sendClientVerificationApi(tokenPayload: jwtPayload) {
await api.emails.sendClientVerification(tokenPayload).catch((error) => {
console.log(error);
});
console.log("sending");
Want results from more Discord servers?
Add your server