响应包含循环引用,无法在 AWS 中序列化为 JSON

Response contains a circular reference and cannot be serialized to JSON in AWS

我正在使用 AWS 开发 API。我正在使用克劳迪娅 API 生成器。

const AWS = require('aws-sdk')
const docClient = new AWS.DynamoDB.DocumentClient()

const createOrder = async (order) => {
    if(!order || !order.id || !order.address ) 
    throw new Error ('To order a pizza you must send a id and the adress of the customer')

    return await docClient.put({
        TableName: 'pizza-order',
        Item: {
            orderId : order.id,
            pizza: order.pizza,
            address: order.address,
            status: 'pending',
        }
    })
}

module.exports = createOrder;

然后我使用邮递员发送请求

{
    "pizza": 1,
    "address": "Bangladesh",
    "id": 2
}

但它 return 像这样的错误:

{ "errorMessage": "Response contains a circular reference and cannot be serialized to JSON" }

有解决办法吗!?

您必须添加 .promise 方法:

return await docClient.put({
    TableName: 'pizza-order',
    Item: {
        orderId : order.id,
        pizza: order.pizza,
        address: order.address,
        status: 'pending',
    }
}).promise().   <== here