Cloudflare Worker throws 500 Internal Error while setting a cookie

Below is a simple event listener code that sets a cookie which throws 500 Internal error. IIf you change the variable to first, it works but not for second. Anyone faced something similar?

addEventListener(‘fetch’, event => {
event.respondWith(handleRequest(event.request))
})

async function handleRequest(request) {

if (request.method === ‘POST’ ) {

let requestbody = await request.text();
var incomingrequest = requestbody.split("|");
var first = incomingrequest[0];
var second = incomingrequest[1];

let response = new Response('Setting cookie works', {
  headers: { 'content-type': 'text/plain',
    'Set-Cookie': `testcookie=${second}; path=/; domain=[.example.com]; secure; HttpOnly; SameSite=Strict`,
    },
    });
    return response;

}
else {
let response = new Response(‘Invalid method’, {
headers: { ‘content-type’: ‘text/plain’ },
});
return response;
}
}