Hi all !
I’m setting up a Netlify serverless function following the documentation here (Get started with functions | Netlify Docs) and am encountering an error when attempting to return a response without a body.
Minimal steps to reproduce:
- Create function file in
./netlify/functions/my_function.js
, to handle all incoming requests and return a simple response without body, i.e., a302
redirect.
my_function.js
:
export default async () => {
return new Response("", {
status: 302,
headers: { Location: "https://newsite.com" },
});
};
export const config = {
path: "/*",
};
Once the function is deployed, every request to the site yields a response 502 Bad Gateway
with a response body: error decoding lambda response: error decoding lambda response: unexpected end of JSON input
.
The error disappears only if one replaces the first argument in the Response
constructor with any non-empty string. This appears to be a bug in the Netlify API, since an empty HTTP response body is valid.
Thank you in advance for any light anyone could shed on this :).