Lambda Node.js获取请求错误:将圆形结构转换为JSON

时间:2018-11-06 14:42:24

标签: node.js lambda

我有以下lambda函数。我正在尝试发出GET请求并返回数据。我收到错误消息“将圆形结构转换为JSON”

有人知道我为什么会得到这个吗?

'use strict';
var http = require('https');

module.exports.hello = async (event, context) => {

  return new Promise((resolve, reject) => {
    const options = {
        host: 'www.somehost.com',
        path: '/somepath',
        headers: {
          'Authorization':'Bearer someBearerToken'
        },
        method: 'GET'
    };

    const req = http.request(options, (res) => {
      console.log("success! data is: ", res)
      resolve(res);
    });

    req.on('error', (e) => {
      reject(e.message);
    }); 

    // send the request
    req.write('');
    req.end();
});

1 个答案:

答案 0 :(得分:0)

删除行

console.log("success! data is: ", res)

res是一个引用其自身的javascript对象。像

一样打印您要检查的特定数据

console.log("success! data is: ", res.data)