gpt4 book ai didi

typescript - 类型错误 : Converting circular structure to JSON --> starting at object with constructor 'ClientRequest'

转载 作者:行者123 更新时间:2023-12-03 13:34:04 27 4
gpt4 key购买 nike

我是一个nest.js 初学者,我正在尝试用我的代码实现Axios,并且发生了这个错误,我想修复它。

    --> starting at object with constructor 'ClientRequest'
| property 'socket' -> object with constructor 'Socket'
--- property '_httpMessage' closes the circle +188941ms
TypeError: Converting circular structure to JSON
--> starting at object with constructor 'ClientRequest'
| property 'socket' -> object with constructor 'Socket'
--- property '_httpMessage' closes the circle
at JSON.stringify (<anonymous>)
at stringify (D:\CUSportcomplex-register\sso-reg\node_modules\express\lib\response.js:1123:12)
at ServerResponse.json (D:\CUSportcomplex-register\sso-reg\node_modules\express\lib\response.js:260:14)
at ExpressAdapter.reply (D:\CUSportcomplex-register\sso-reg\node_modules\@nestjs\platform-express\adapters\express-adapter.js:24:57)
at RouterResponseController.apply (D:\CUSportcomplex-register\sso-reg\node_modules\@nestjs\core\router\router-response-controller.js:13:36)
at D:\CUSportcomplex-register\sso-reg\node_modules\@nestjs\core\router\router-execution-context.js:173:48
at processTicksAndRejections (internal/process/task_queues.js:93:5)
at async D:\CUSportcomplex-register\sso-reg\node_modules\@nestjs\core\router\router-execution-context.js:47:13
at async D:\CUSportcomplex-register\sso-reg\node_modules\@nestjs\core\router\router-proxy.js:9:17
这是我的 app.service.ts
async validateSSO(appticket): Promise<SsoContent> {
let instance = axios.create({
baseURL: "http://localhost:8080/",
headers: {
'DeeAppId': config.DeeAppId,
'DeeAppSecret': config.DeeAppSecret,
'DeeTicket': appticket
}
});
instance.get("/serviceValidation")
.then(response => {
this.ssoContent = response;
})
.catch(error => {
return (error);
});

return this.ssoContent;

}
这是我的 app.controller.ts
    @Get('validation/:appticket')
async validateSSO(
@Param('appticket') appticket: string
//DeeAppTicket is sented via Front-end
): Promise<SsoContent> {
return this.registeringService.validateSSO(appticket);
}
感谢您的帮助 :)

最佳答案

首先,nest.js 为您提供了开箱即用的 HttpService,您可以通过 DI 注入(inject)它:
https://docs.nestjs.com/techniques/http-module
其次 - 您正在尝试存储整个响应对象,它是复杂的数据结构并包含错误消息中所述的循环依赖项(TypeError:将循环结构转换为 JSON)
您应该做的是映射您需要的数据而不是存储整个圆形对象,
或者您应该查看一些可以解析循环 json 的库:https://www.npmjs.com/package/flatted

关于typescript - 类型错误 : Converting circular structure to JSON --> starting at object with constructor 'ClientRequest' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64735881/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com