Function works locally but wont POST with axios, doesn't log any errors or exceptions

My netlify site is vibrant-northcutt-f52256.netlify.app.
I’ve followed this guide (Automate Order Fulfillment w/ Stripe Webhooks & Netlify Functions) to create a webhook for Stripe using JS. Instead of Sengrid to send emails to my fulfilment provider, I’m using their API, so I’m making a POST request using axios.

Locally, I’m testing everything with the Stripe forwarding (as per the blog post) and ntl dev and everything works like a charm: no errors, no problems. The order is created as it should.

In prod I see log messages up to the point where I POST. Here’s a snippet:

            console.log("POSTing data to fulfillment");  // PRINTS IN LOG
            axios(axiosconfig)
                    .then(function (response) {
			console.log("INSIDE THE RESPONSE");   // DOES NOT PRINT IN LOG
			console.log(JSON.stringify(response.data));

And that’s it. I see that final message before axios does its thing, then just

Jul 25, 05:10:24 PM: 0bc7d830 INFO   POSTing data to fulfillment
Jul 25, 05:10:25 PM: 0bc7d830 Duration: 429.16 ms	Memory Usage: 78 MB	Init Duration: 351.53 ms

:person_shrugging: what’s up? Is it forbidden to POST from a function? I’m just baffled by the lack of any feedback. If something is breaking, there should be an error message. The try catch does nothing either.

@jcpsantiago Do you have a .catch in your promise chain?

I know that you mention the error message not being caught by try/catch, but if you’ve wrapped the call in a traditional try/catch block that won’t work unless you’re using async/await.

If you haven’t already, you could try adding a catch into the chain after your then:

.then(response => {
})
.catch(error => {
  console.error(error);
})

After trying multiple things, this answer did the trick Netlify Functions + axios Get not working in production - #2 by hrishikesh

Essentially adding returning the axios promise

            console.log("POSTing data to fulfillment");
            return axios(axiosconfig). // <- here
                .then(function (response) {
                    const res = response.data;
                    const res_str = JSON.stringify(res);
......
1 Like

Thanks for coming back and sharing this solution! This will help folks who encounter something similar.

Happy building :rocket: