Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

1.6K
Visualizações
node:internal/errors:464 ErrorCaptureStackTrace(err); ^ Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client

Why do I keep getting this error? Iam using nodejs, and am not that familiar with backend programming, so I cant really know whats going on, If anyone is fimiliar with this error or knows what causing, PLEASE HELP ME🙏🙏😌

Here is my code??

    async function verify() {
        const ticket = await client.verifyIdToken({
            idToken: token,
            audience: CLIENT_ID,  // Specify the CLIENT_ID of the app that accesses the backend
        });
        const payload = ticket.getPayload();
        const userid = payload['sub'];
      }
      verify()
      .then(()=>{
          res.cookie('session-token', token);
          res.send('success')
      })
      .catch(console.error);

})

const stripe = require('stripe')(process.env.STRIPE_PRIVATE_KEY)


app.post("/create-checkout-session", async (req,res)=>{
    try{
const session = await stripe.checkout.sessions.create({
payment_method_types:['card'],
mode:'payment',
line_items: req.body.items.map(item=>{
    
    return{
        price_data:{
            currency:item.currency,
            product_data:{
                name:item.name
            },
            unit_amount: item.priceInCents,
        },
        quantity:item.quantity
    }
}),
success_url:`${process.env.SERVER_URL}/success.html`,
cancel_url:`${process.env.SERVER_URL}/cancel.html`
})
res.json({url:session.url})
    }catch(e){
res.status(500).json({error:e.message})
    }
    
    res.json({url:'Hi'})
})````
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

you are trying to set Http headers after they are sent.

This error is occuring because your code is using res.json in both try and catch blocks. It means res.json() will be executed no matter error occurs or not. Which sends json response.

Then you are using res.json outside the try/catch blocks, it means you're trying to send response after it is already sent.

And that is causing this error.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda