0

我正在使用 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
}

但它返回一个像这样的错误:

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

有什么解决办法!?

4

1 回答 1

1

您必须添加.promise方法:

return await docClient.put({
    TableName: 'pizza-order',
    Item: {
        orderId : order.id,
        pizza: order.pizza,
        address: order.address,
        status: 'pending',
    }
}).promise().   <== here
于 2021-04-27T07:13:21.647 回答