【发布时间】:2019-07-19 00:06:48
【问题描述】:
我的 Apollo 客户端无法收到任何网络错误,只有 GraphQL 错误。
我的客户端是这样设置的:
const errorLink = onError(({ graphQLErrors, networkError }) => {
if (graphQLErrors)
graphQLErrors.map(({ message, locations, path }) =>
console.log(`[GraphQL error]: Message: ${message}, Location: ${locations}, Path: ${path}`)
);
if (networkError) console.log(`[Network error]: ${networkError}`);
});
const client = new ApolloClient({
link: ApolloLink.from([
errorLink,
new HttpLink({
uri: 'http://localhost:4000/graphql'
}),
]),
});
在服务器上我发出一个请求,我会这样解析:
.then(res => {
if (res.ok) {
return { blah: res.json(), count };
}
throw new Error();
})
.catch(error => {
throw new AuthenticationError('Must Authenticate');
});
AuthenicationError 只是作为 GraphQL 错误冒泡到客户端([GraphQL error]: Message: Must Authenticate,,我基本上只是希望能够在客户端从服务器请求中获取 HTTP 状态代码。
谢谢
【问题讨论】:
标签: express graphql apollo apollo-client apollo-server