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

150
Visualizações
InternalServerError: Converting circular structure to JSON

I got a problem with my app, anyone can help me ? Here is my code :

static me = async (req, res, next) => { 
        try {
            const returnDB = await user.me(req, res, next);
            res.status(200).json({
                status: true, 
                message: 'This user',
                returnDB
            })
        } catch (e) {
            next(createError(e.statusCode, e.message))
        }
    }

And here is my error :

InternalServerError: Converting circular structure to JSON
    --> starting at object with constructor 'Socket'
    |     property '_writableState' -> object with constructor 'WritableState'
    |     property 'afterWriteTickInfo' -> object with constructor 'Object'
    --- property 'stream' closes the circle
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

A circular reference ossurs when A refers to B and B refers to A (you can add more steps, if you like). That is no problem for JavaScript, but when you try to write such a setting down to JSON, you end up with an eternal loop.

In your case, the object returnDB refers to res

const returnDB = await user.me(req, res, next);

And res gets the JSON assigned that includes returnDB.

res.status(200).json({
    ...,
    returnDB
})

The error message tells you what attribute of which objects exactly refers to which other object.

Probably, you do not want to include the whole returnDB object in the response, but only some specific attribute of the object?

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