Thank you. Now I have updated it to see the error.
First here’s the fixed code just to make sure it seems right.
import fetch from 'node-fetch';
const handler = async function (event) {
if (event.body === null) {
return {
statusCode: 400,
body: JSON.stringify("Payload required"),
};
}
const formData = JSON.parse(event.body);
try{
await fetch(`\${process.env.URL}/.netlify/functions/emails/sendGridEmail`, {
headers: {
"netlify-emails-secret": process.env.NETLIFY_EMAILS_SECRET,
},
method: "POST",
body: JSON.stringify({
from: "from",
to: "to",
subject: "test Subject",
parameters: {
name: formData.name,
city: formData.city,
state: formData.state,
homePhone: formData.homePhone,
cellPhone: formData.cellPhone,
email: formData.email,
},
}),
});
if(!response.ok){
return{
statusCode: response.status,
body: JSON.stringify(`Email failed to send: ${await response.text()}`),
};
}
return {
statusCode: 200,
body: JSON.stringify("Email sent!"),
};
}
catch(error){
return{
statusCode: 500,
body: JSON.stringify(`Server error: ${error}`)
}
}
};
export default { handler };
Then here’s the error. It seems as though it is trying to call a lambda function but it does not exist. I assume this means that either something is not being called from the correct path or a file is made incorrectly.
Request from ::1: POST /.netlify/functions/sendgrid
{“level”:“error”,“message”:“End - Error:”}
{“errorMessage”:“lambdaFunc[lambdaHandler] is not a function”,“errorType”:“TypeError”,“level”:“error”,“stackTrace”:[“Object._executeSync (C:\Users\adamp\AppData\Roaming\npm\node_modules\netlify-cli\node_modules\lambda-local\build\lambdalocal.js:295:47)”,“C:\Users\adamp\AppData\Roaming\npm\node_modules\netlify-cli\node_modules\lambda-local\build\lambdalocal.js:95:26”,“new Promise ()”,“Object.execute (C:\Users\adamp\AppData\Roaming\npm\node_modules\netlify-cli\node_modules\lambda-local\build\lambdalocal.js:87:16)”,“Module.invokeFunction (file:///C:/Users/adamp/AppData/Roaming/npm/node_modules/netlify-cli/src/lib/functions/runtimes/js/index.mjs:60:36)”,“NetlifyFunction.invoke (file:///C:/Users/adamp/AppData/Roaming/npm/node_modules/netlify-cli/src/lib/functions/netlify-function.mjs:124:41)”,“processTicksAndRejections (node:internal/process/task_queues:96:5)”,"handler (file:///C:/Users/adamp/AppData/Roaming/npm/node_modules/netlify-cli/src/lib/functions/server.mjs:1Response with status 500 in 224 ms.
Request from ::1: POST /.netlify/functions/sendgrid
{“level”:“error”,“message”:“End - Error:”}
{“errorMessage”:“lambdaFunc[lambdaHandler] is not a function”,“errorType”:“TypeError”,“level”:“error”,“stackTrace”:[“Object._executeSync (C:\Users\adamp\AppData\Roaming\npm\node_modules\netlify-cli\node_modules\lambda-local\build\lambdalocal.js:295:47)”,“C:\Users\adamp\AppData\Roaming\npm\node_modules\netlify-cli\node_modules\lambda-local\build\lambdalocal.js:95:26”,“new Promise ()”,“Object.execute (C:\Users\adamp\AppData\Roaming\npm\node_modules\netlify-cli\node_modules\lambda-local\build\lambdalocal.js:87:16)”,“Module.invokeFunction (file:///C:/Users/adamp/AppData/Roaming/npm/node_modules/netlify-cli/src/lib/functions/runtimes/js/index.mjs:60:36)”,“NetlifyFunction.invoke (file:///C:/Users/adamp/AppData/Roaming/npm/node_modules/netlify-cli/src/lib/functions/net59:33)”]}
Response with status 500 in 21 ms.
Here’s the directory in case this helps