My project is around a website on netlify, so i'm using netlify-lambda in this example.
I'm working with async/wait since i need to do a few calls to the database, keeping the code clean. When the exports handler is async, the callback function no longer works correctly. You will get Cannot read property 'statusCode' of undefined
and the code will continue so your serverless function will crash with error "Write after end" so i have to return to give back the error msg or the success msg when the code is done.
But if i have to return from within another function/promise then i can't return the data to the previous function, it just crashes my api. I'm quite new to serverless functions, i litterally started using it yesterday. Any help would be appreciated :)
exports.handler = async function (event, context, callback) {
......More code
mg.messages().send(email, function (error, body) {
if (error) {
return { statusCode: 500, body: error };
} else {
return { statusCode: 200, body: "Email var sendt" };
}
});
}