axios.post() 关于圆形结构的错误

use*_*155 4 node.js axios expo

如果我没有正确使用 axios,请指导我。这段简单的代码可以直接运行:

const axios = require('axios')

axios.post('https://exp.host/--/api/v2/push/send', {"to":["ExponentPushToken[xxxxxxx]"],"title":"test title","body":"test body."})
  .then(responseExpo => {
     console.log("expo replied normally: " + JSON.stringify(responseExpo));
  })
  .catch(error => {
    console.log("expo replied with error: " + JSON.stringify(error,null,4));
  });
Run Code Online (Sandbox Code Playgroud)

结果是:

Promise { <pending> }
expo replied with error: {}
Run Code Online (Sandbox Code Playgroud)

"axios": "^0.19.2"

我尝试使用 api 工具发布并看到带有正常 200 状态代码的响应:

{
  "data":[
  {
    "status": "error",
    "message": "\"ExponentPushToken[xxxxxxx]\" is not a registered push notification recipient",
    "details":{
      "error": "DeviceNotRegistered"
    }
  }
  ]
}
Run Code Online (Sandbox Code Playgroud)

(您可能会忽略此 json 中的“错误”:“DeviceNotRegistered”,因为这是预期的,因为我在调用 api 时输入了无效的 xxxxx 输入值。即使输入有效的输入值,结果仍然返回到带有空错误的 catch 块)

我期待它返回到 then 块因为服务器实际响应 200 并带有格式良好的 json 结果。
我做错了什么以至于调用返回到 catch 块吗?因为错误是空的,我不知道出了什么问题。

============================== 经过jfriend的提醒我改成直接显示错误。

console.log("expo 回复错误:" + error);

现在是这样的:

Promise { <pending> }
expo replied with error: TypeError: Converting circular structure to JSON
    --> starting at object with constructor 'ClientRequest'
    |     property 'socket' -> object with constructor 'TLSSocket'
    --- property '_httpMessage' closes the circle
Run Code Online (Sandbox Code Playgroud)

任何人都可以让我知道它的确切含义并指导我如何纠正我的用法?

use*_*155 6

(问题已解决)。响应(问题中的 responseExpo)既不是纯数据 JSON,也不是纯字符串。它是一个具有(参见 github.com/axios/axios#response-schema)一些属性的对象。真正的响应内容在“response.data”里面。我错误地将响应视为普通的 json 对象或 http 响应内容。