插件调用OpenAPI解包失败

Viewed 16

使用JSON.stringifyFetchAsAdmin返回的结果进行解包,出现错误

Converting circular structure to JSON\n --> starting at object with constructor 'ClientRequest'\n | property 'socket' -> object with constructor 'Socket'\n --- property '_httpMessage' closes the circle"}

代码如下:

import { FetchAsAdmin } from '@ones-op/fetch'
// ...
try {
    const porjectsResp = await FetchAsAdmin({
      url: `/openapi/v2/project/projects`,
      method: 'GET',
      params: {
        teamID: 'B5QqUH4h',
      },
      headers: {
        Accept: 'application/json',
      },
    })

    Logger.info('porjectsResp:', porjectsResp.data)
    JSON.stringify(porjectsResp) // 报错
  } catch (e) {
    Logger.error(`porjectsResp`, e)
  }
1 Answers

porjectsResp.data 可以打印日志或者用 JSON 序列化。

porjectsResp 对象上含有互相指向的内部属性,因此不能直接对 porjectsResp 进行JSON 序列化。