Lo sé, esta pregunta se ha hecho un montón de tiempo. Pero realmente no sé qué está mal con mi código aquí. ¿Cómo puedo solucionar este tipo de error?
¿Dónde tengo una estructura circular?
Estoy ejecutando este código en una función AWS Lambda:
const addRanksToDB = async (tableName, stats) => { return Promise.all(Object.keys(stats).map(async (slug) => { const projectSlug = slug; const rankData = stats[slug]; const messageBody = { rowId: projectSlug, table: tableName, identifier: 'project_slug', action: 'insert', payload: { project_slug: projectSlug, ...rankData, last_updated: knexClient.fn.now(), }, }; return sqs.sendMessage({ MessageBody: JSON.stringify(messageBody), QueueUrl: 'https://sqs.eu-central-1.amazonaws.com/599632852002/handleDataInDBQueue', }).promise(); })); }; El objeto rankData se ve así:
{ one_day_volume: 191, seven_day_volume: 162, thirty_day_volume: 179, total_volume: 156, num_owners: 4, average_price: 129, market_cap: 66, floor_price: 146 }Y este es el error que me sale:
{ "errorType": "TypeError", "errorMessage": "Converting circular structure to JSON\n --> starting at object with constructor 'Timeout'\n | property '_idlePrev' -> object with constructor 'TimersList'\n --- property '_idleNext' closes the circle", "trace": [ "TypeError: Converting circular structure to JSON", " --> starting at object with constructor 'Timeout'", " | property '_idlePrev' -> object with constructor 'TimersList'", " --- property '_idleNext' closes the circle", " at JSON.stringify (<anonymous>)", " at /var/task/src/handlers/stats/webpack:/handlers/stats/rankProjectsByStatsCronjob.js:84:27", " at Array.map (<anonymous>)", " at v (/var/task/src/handlers/stats/webpack:/handlers/stats/rankProjectsByStatsCronjob.js:67:43)", " at Runtime.R [as handler] (/var/task/src/handlers/stats/webpack:/handlers/stats/rankProjectsByStatsCronjob.js:188:23)", " at processTicksAndRejections (internal/process/task_queues.js:95:5)" ] } El error apunta a la línea con MessageBody: JSON.stringify(messageBody), . ¿Cómo puedo estructurar mi mensaje sqs para que no reciba este error?