NodeJS 无法打印完整的RejectedRecords

mzsu5hc0  于 2023-06-22  发布在  Node.js
关注(0)|答案(1)|浏览(115)

我试着把记录写入我的时间流数据库。我的问题是,我得到了一个Cannot read httpResponse的undefined,即使我做了他们在指南中描述的同样的事情:https://docs.aws.amazon.com/timestream/latest/developerguide/code-samples.write.html#code-samples.write.rejectedRecordException

const timestreamParams = {
      DatabaseName: db_name,
      TableName: TimeSpanRawE[table_name],
      Records: chunk,
    }
    let request = writeClient.writeRecords(timestreamParams).promise()
    await request.then(
      (data) => {
        return ok(data)
      },
      (error) => {
        console.log('Error writing records:', error)
        if (error.code === 'RejectedRecordsException') {
          const responsePayload = JSON.parse(
            //@ts-ignore
            request.response.httpResponse.body.toString()
          )
          console.log('RejectedRecords: ', responsePayload.RejectedRecords)
          console.log('Other records were written successfully. ')
        }
        return err({ error, params })
      }
    )

那么,我如何阅读错误消息?

wwwo4jvm

wwwo4jvm1#

您定义的请求变量不正确。promise不应该包含在request变量中。应该是这样的:

let request = writeClient.writeRecords(timestreamParams).promise()

promise可以这样调用:

await request.promise().then( 
   ...
)

相关问题