You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Timestream写入记录遇Cannot read httpResponse of undefined,如何读取错误信息?

解决Timestream写入时无法读取RejectedRecords的问题

你遇到的Cannot read httpResponse of undefined错误,根源是调用.promise()后,request变量变成了Promise实例,不再持有原始请求的response属性。AWS SDK抛出的RejectedRecordsException错误对象本身就包含了拒绝记录的详细信息,不需要手动解析响应体。

修改后的代码如下:

const timestreamParams = {
  DatabaseName: db_name,
  TableName: TimeSpanRawE[table_name],
  Records: chunk,
}

try {
  const data = await writeClient.writeRecords(timestreamParams).promise();
  return ok(data);
} catch (error) {
  console.log('Error writing records:', error);
  if (error.code === 'RejectedRecordsException') {
    // 直接从错误对象中读取拒绝记录
    console.log('RejectedRecords: ', error.rejectedRecords);
    console.log('Other records were written successfully. ');
  }
  return err({ error, params: timestreamParams });
}

关键修改点:

  • 改用try/catch替代then/catch,避免Promise实例与原始请求对象混淆
  • 直接访问error.rejectedRecords获取拒绝记录,无需依赖request.response
  • 代码逻辑更清晰,彻底消除httpResponse undefined的报错

内容的提问来源于stack exchange,提问作者Ilijanovic

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.19 02:23:11