我正在尝试找出我在这段代码中做错了什么,但你不能解决它。我需要在getInitialPops中使用我的query.id来处理一些内容。fetch可以工作,但在我的catch中我收到了这个错误:
FetchError: invalid json response body at https://url/resume-true.json reason: Unexpected token < in JSON at position 0原始端点具有:
https://url/resume-${query.id}.json当我console.log query.id返回时,首先
slug-5 (this is the rigth one)第二:
true (I dont'know were this came from)这是我的getInitialProps
channelRouter.getInitialProps = async ({ query }) => {
console.log("query**", query.id);
try {
const res = await fetch(
`https://url/resume-${query.id}.json`
);
let data = await res.json();
return { data };
} catch (e) {
console.log(`${e}`);
}
};有什么想法吗?谢谢!!
发布于 2020-02-01 22:51:07
我以前见过很多次这个错误。
FetchError: invalid json response body at https://url/resume-true.json reason: Unexpected token < in JSON at position 0
这意味着您的端点将返回超文本标记语言而不是JSON (因此以<开头)
检查你的终结点,它不是有效的json,可能是404或500状态
https://stackoverflow.com/questions/60017944
复制相似问题