Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

1.6K
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda