#Prevent ERROR 500 AND 504 BAD GATEWAY on Hobby Tier

4 messages · Page 1 of 1 (latest)

rigid dawn
#
const mail = require('@sendgrid/mail');

mail.setApiKey(process.env.SENDGRID_API_KEY);

export default async (req: { body: any; }, res: { status: (arg0: number) => { (): any; new(): any; json: { (arg0: { status: string; }): void; new(): any; }; }; }) => {
  const body = req.body;

  const message = `
    Name: ${body.name}\r\n
    Email: ${body.email}\r\n
    Message: ${body.message}
`;

  const data = {
    to: process.env.EMAIL_ID,
    from: '[email protected]',
    subject: 'New message from Contact Form',
    text: message,
    html: message.replace(/\r\n/g, '<br>'),
  };

  try {
    await mail.send(data);
    res.status(200).json({ status: 'Ok' });
    return { success: true}
  }
  catch (error) {
    res.status(500).json({ status: "ERROR 500: INTERNAL_SERVER_ERROR An error occured while sending the email"})
    res.status(504).json({ status: "ERROR 500: BAD_GATEWAY An error occured while sending the email"})
  }
};
#

Here is my code

rigid dawn
#

I've gone ahead and changed data centre locations through vercel to see if that will have an impact

fresh shard
#

Did it help?