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

206
Visualizações
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 Respostas
Responde à pergunta

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 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