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