[Form] Use submission-created.js return value

I created a newsletter form, which is server-side rendered and so far works fine. The form is submitted via an AJAX POST request, but it also has an action attribute pointing to a custom thank you page, in case the user has JS disabled.

In my submission-created.js function I successfully call the newsletter service and add a new subscriber. But I also want to tackle a few edge cases, e.g. the newsletter service is down, or the user already exists. I added the checks in the lambda function, and for those cases, I return different HTTP codes/response bodies.

The problem is that in the front end, after submitting the form, I don’t get any of these custom HTTP responses from the lambda function. Instead, I get a HTTP 200 with the contents of the custom thank you page.

Is there a way of getting in the front-end the HTTP response that I return in the lambda function?

Thank you

Not that I’m aware of.

The HTTP 200 result is sent by our form handling service; and your function runs only AFTER we’ve accepted the submission and returned that 200. In short, that function can’t return an error that prevents acceptance of the already-accepted submission. You could of course run the function somehow before submitting the form data, but as you point out, that is unlikely to be easy to configure if you want to catch the javascript-disabled folks (you’d need a multi-step submit and I guess storing intermediary data in a cookie, or in a series of forms?)