Netlify form function callback


I have a netlify function running from submission-created.js

So from the client side, I have something like this for the submit event listener:

const processForm = form => {
    const data = new FormData(form)

fetch('/', {
  method: 'POST',
  body: data
}).then(response => {
}).catch(error => {

In the lambda function:

    .then( data => {
            callback(null, {
                statusCode: 201,
                body: "All done!"
    .catch ( error => {
            callback(null, {
                statusCode: 500,
                body: "Something went wrong! :( "

When triggering the form, the function seems to deploy and everything seems to be working fine.
However, in my client side eventlistener, I always get a 200 and response.ok=true :confused:
Even when the lambda function should be sending a callback with 201 or 500. The function seems to be doing its thing accordingly, if an error is thrown it does hit the catch, so I’m assuming i’m doing something trivial incorrectly?
Any hints and clues would be very much appreciated!

Hey @realcodeworld and welcome :wave: (and great handle),
I think this is happening because these two are not connected- you’re expecting to log the response from your function in your client code, but what you’re logging instead is the response from the form submission being POSTed to Netlify.

Once a form is successfully submitted to your Netlify site, we separately trigger the submission-created.js function.

If you check the Functions tab in your Netlify dashboard, you’ll probably see the status and body you expect based on what’s in your function code. Some things people usually use the submission-created.js event function for is to send an email to themselves or maybe update some kind of count in a database somewhere.

Let us know if this answers your question or if we can help further! For further function debugging, it’d be great if you could share your Netlify URL so we can check out your site dashboard.