我在Node应用程序中有以下函数:
中间件
const recachePosts: any = async (req: Request, res: Response, next: NextFunction) => {
try {
const status = await cachePosts();
...
} catch (err: any) {
return res.status(422).json({
status: false,
message: err.message,
});
}
}
const cachePosts = async () => {
const posts: any = await fetchAllPosts();
...
}
字符串
服务功能:
const fetchAllPosts = async () => {
console.log('Step 1');
const posts: any = await axios.get(`https://url.com`);
console.log('Step 2: ' + posts);
// returns Step 2: [Object Object]
console.log('Step 2: ' + JSON.stringify(posts));
// returns TypeError: Converting circular structure to JSON
return posts;
};
型
service函数中的const posts: any = await axios.get(
https://url.com );
行似乎不起作用。我做错什么了?
1条答案
按热度按时间ddrv8njm1#
加载post的数据或状态变量,因为posts实际上是axios响应对象
字符串