i'm using Netlify serverless functions.
when I run JSON.parse on the event.body response I get SyntaxError: Unexpected end of JSON input
My client side code is as follows:
const items = [{ id: 'prod_LvqkrsI9O5F0xJ' }];
async function initialize() {
const response = await fetch('/.netlify/functions/createPaymentIntent', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ items }),
});
console.log(response);
const { clientSecret } = await response.json();
Server side code is as follows:
exports.handler = async (event, context) => {
const items = await JSON.parse(event.body);
console.log('items', items);
the console logs out
items { items: [ { id: 'prod_LvqkrsI9O5F0xJ' } ] }
...{"level":"error","message":"End - Error:"}
{"errorMessage":"Unexpected end of JSON input","errorType":"SyntaxError","level":"error",...
Any ideas please?