gpt4 book ai didi

react-native - react Apollo 错误 : Network error: Unexpected token < in JSON at position 1

转载 作者:行者123 更新时间:2023-12-01 03:17:36 25 4
gpt4 key购买 nike

我想通过 Apollo 向此服务器发送请求并获取查询:
const client = new ApolloClient({
link: new HttpLink({
uri:
' http://mfapat.com/graphql/mfaapp/ ' }),
cache: new InMemoryCache()

})
const FeedQuery = gql
query{
allFmr{
fmrId,
name,
studio,
bedRm1,
bedRm2,
bedRm3,
bedRm4
}
}
`
但我正面临此错误消息:

未处理(在 react-apollo:Apollo(FMRScreen) 中)错误:网络错误:位置 1 处的 JSON 中出现意外 token <

at new ApolloError (http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:109336:32)
at ObservableQuery.currentResult (http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:109447:28)
at GraphQL.dataForChild (http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:103192:66)
at GraphQL.render (http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:103243:37)

....

但是我可以轻松地在浏览器中打开“ http://mfapat.com/graphql/mfaapp/ ”并进行查询。有谁知道问题出在哪里?

最佳答案

现在,Apollo 将从服务器发送的所有内容都视为 JSON。但是,如果出现错误,则您的服务器可能会发送 HTML 以显示基本错误页面。

要查看错误,请打开您的开发工具,然后查看网络选项卡。这显示了一个示例 401 错误:

401 error in dev tools

如您所见,如果您将其解析为 JSON,您会偶然发现第一个字符:<这就是我们的错误信息的来源。

阅读发送的特定错误使您能够修复错误。

要修复一般错误,请将您的服务器配置为针对 HTTP 错误发送 JSON,而不是 HTML 代码。这应该允许 Apollo 解析它并显示一个合理的错误页面。

编辑:另见 this discussion - 希望他们会改变默认的 Apollo 行为,或者至少提供有用的讨论。

关于react-native - react Apollo 错误 : Network error: Unexpected token < in JSON at position 1,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47950455/

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