Nest 29840-将循环结构转换为JSON的ExceptionsHandler



NextJS在处理http帖子时出现后端问题,导致将循环结构转换为JSON错误。

以下是详细说明问题的代码堆栈跟踪

[Nest] 29840   - 01/04/2021, 2:46:31 PM   ExceptionsHandler Converting circular structure to JSON
--> starting at object with constructor 'ClientRequest'
|     property 'socket' -> object with constructor 'TLSSocket'
--- property '_httpMessage' closes the circle +199712ms
TypeError: Converting circular structure to JSON
--> starting at object with constructor 'ClientRequest'
|     property 'socket' -> object with constructor 'TLSSocket'
--- property '_httpMessage' closes the circle
at JSON.stringify (<anonymous>)
at stringify node_modulesexpresslibresponse.js:1123:12)
at ServerResponse.json node_modulesexpresslibresponse.js:260:14)
at ExpressAdapter.reply node_modules@nestjsplatform-expressadaptersexpress-adapter.js:24:57)    
at RouterResponseController.apply node_modules@nestjscorerouterrouter-response-controller.js:13:36)
at node_modules@nestjscorerouterrouter-execution-context.js:173:48
at processTicksAndRejections (internal/process/task_queues.js:94:5)
at async node_modules@nestjscorerouterrouter-execution-context.js:47:13
at async node_modules@nestjscorerouterrouter-proxy.js:9:17

找到解决方案需要一些时间,但可以通过添加以下代码来解决此问题

this.http.post(https://api-enpont,body,headerData(.pipe(map(response=>response.data((;

不要忘记从"rxjs/operators"导入{map};

最新更新