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

207
Vistas
How to get actual content when JSON.stringify shows empty object but in actual fact, it isn't empty

I am trying to log my errors and send notification to a channel. When I use console.log() I get a description of the error message but when I use JSON.strigify it returns an empty object. How can I fix this issue please.

When I run this code:

console.log(err);
console.log("stringify", JSON.stringify(err));

I get this response:

ReferenceError: School is not defined
    at /Users/macbookpro/Documents...
    at Layer.handle [as handle_request] (/Users/macbookpro/Documents...
    at next (/Users/macbookpro/Documents...
    at adminAccess (/Users/macbookpro/Documents...
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
strinfify {}

I need the error message, and for me to send it successfully using axios, I need to JSON.stringify() the error message.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Most properties on an error object are non-enumerable, so you need to do something like this:

let error = new Error('nested error message');

console.log(JSON.stringify(error))
console.log(JSON.stringify(Object.assign({}, 
      error,
      {      // Explicitly pull Error's non-enumerable properties
        name: error.name, 
        message: error.message, 
        stack: error.stack
      }
    )))

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