【问题标题】:How do I solve “TypeError: Converting circular structure to JSON” in NodeJS?如何解决 NodeJS 中的“TypeError:将循环结构转换为 JSON”?
【发布时间】:2021-10-21 19:38:44
【问题描述】:

我正在测试我在 postman 中编写的代码。它给出了 400 错误,但我可以在 api 中创建带有测试标题的作业

我有两个文件。当我调试我的代码时,它最迟会给出 400 错误。

me.route

    router.post('/Integrations',  async function (req, res, next) {
    try {
        const result = await zohoService.getIntegrations(
            req.body.title,
            req.body.empNameSurname,
            req.body.points,
            req.body.knowledge,
            req.body.level,
            req.body.oldTitle,
            req.body.newTitle,
            req.body.oldSalary,
            req.body.newSalary,
            req.body.team,
            req.body.priority
        );
        return res.status(200).send({result});
    }
    catch (e) {
        return res.status(400).json({status: false, message: `${e}`});
    }
})

zoho.services

async function getIntegrations(title,empNameSurname,points,knowledge,level,oldTitle,newTitle,oldSalary,newSalary,team,priority, tried=0){
    if(tried===3)
        throw new Error("Can not get new token");
    try {
        const url = encodeURI(`https://coreapi.qntrl.com/blueprint/api/examplegroup/job?title=${title}&layout_id=63746576744247&customfield_shorttext79=${empNameSurname}&customfield_integer15=${points}&customfield_shorttext89=${knowledge}&customfield_shorttext46=${level}&customfield_shorttext61=${oldTitle}&customfield_shorttext4=${newTitle}&customfield_decimal3=${oldSalary}&customfield_decimal2=${newSalary}&customfield_shorttext91=${team}&priority=${priority}`)
        const data =  await axios({
            method: 'post',
            url: url,
            headers: { Authorization: `Bearer ${accessToken}`}
        });
        return data ;
    }catch (e) {
        if(e.response.status===401)
        {
            await generateToken(refreshToken);
            return await getIntegrations(title,empNameSurname,points,knowledge,level,oldTitle,newTitle,oldSalary,newSalary,team,priority, ++tried);
        }
    }
}

有人知道是什么原因造成的吗?

【问题讨论】:

    标签: node.js postgresql docker express sequelize.js


    【解决方案1】:

    您确定通过 Axios 调用获得的数据是有效的 JSON 吗?如果不是,则可能会发生这种情况。

    如果它是 Sequelize 查询并且您没有使用 raw: true,您可能必须显式返回仅包含所需信息的对象或使用 JSON.parse(JSON.stringify(result)) 强制转换它

    【讨论】:

      猜你喜欢
      • 2020-02-03
      • 2022-01-11
      • 1970-01-01
      • 2015-01-21
      • 2014-01-21
      • 1970-01-01
      • 1970-01-01
      • 2017-06-29
      • 2018-10-05
      相关资源
      最近更新 更多