【发布时间】:2021-10-20 23:11:41
【问题描述】:
我在 getStaticProps 中有多个 API 调用。我想单独处理每个 API 调用的错误。我该怎么做?
export async function getStaticProps(context) {
const fund = context.params.fund;
const avggReturnsRes = await fetch(
https://localhost:8000/avggaut/?name=${fund}
);
const avggReturnsResult = await avggReturnsRes.json();
const navPlotRes = await fetch(
https://localhost:8000/navplot/?name=${fund}
);
const navPlotResult = await navPlotRes.json();
return {
props: {
fund: fund,
avggReturnsResult: avggReturnsResult,
navPlotResult: navPlotResult,
},
};
}
【问题讨论】:
-
你到底想要什么??
-
每次API调用出现错误怎么办?
标签: next.js fetch getstaticprops