I have a Netlify function that is scheduled to run every minute using the schedule method from the @netlify/functions package. The function makes API calls and logs the response using console.log("response: ", response.data);. However, I'm not seeing any output from this console.log statement in the Netlify function logs.
Here's the code for my function:
import { Handler, HandlerEvent, HandlerContext, schedule } from "@netlify/functions";
import { dbIndex } from "src/app/dbIndex";
import { RestAPIService } from "src/service/RestAPI.service";
const getData: Handler = async (event: HandlerEvent, context: HandlerContext) => {
console.log("Received event:", event);
try {
const responses = [];
for (let i = 0; i < dbIndex.length; i++) {
const response = await RestAPIService.fetchTransactions({
id: dbIndex[i].id,
merch: dbIndex[i].merch,
date: dbIndex[i].date,
});
console.log("response->>>: ", response.data);
responses.push(response.data);
}
return {
statusCode: 200,
}
} catch (e) {
return {
statusCode: 500,
message: e
}
}
};
const handler = schedule("* * * * *", getData)
export { handler };
I only can see console.log("Received event:", event);
after I try to run this function locally everything works fine, I can see logs.
I've tried the following troubleshooting steps:
None of these steps have solved the issue. What could be causing this problem, and how can I fix it?
I believe your function throwing an exception. Try to add a console.log on a catch like that:
try {
...
} catch (e) {
console.log({ e });
return {
statusCode: 500,
message: e
}
}