Apollo的onErrorforward(operation)不起作用
创始人
2024-09-09 08:30:44
0
  1. 检查是否正确定义了 onError 函数,格式为:
const client = new ApolloClient({
  uri: 'your graphql uri',
  onError: ({ networkError, graphQLErrors }) => {
    // 处理错误
  },
});
  1. 确认 onError 函数中是否有 forward 方法,格式为:
const client = new ApolloClient({
  uri: 'your graphql uri',
  onError: ({ networkError, graphQLErrors, forward }) => {
    // 处理错误
    return forward(operation);
  },
});
  1. 如果仍然无法正常工作,尝试在 onError 函数中使用 ApolloLink.from 中间件,例如:
const errorLink = onError(({ graphQLErrors, networkError }) => {
  if (graphQLErrors) {
    graphQLErrors.forEach(({ message, locations, path }) =>
      console.log(
        `[GraphQL error]: Message: ${message}, Location: ${locations}, Path: ${path}`,
      ),
    );
  }
  if (networkError) console.log(`[Network error]: ${networkError}`);
});

const httpLink = createHttpLink({
  uri: '/graphql',
});

const client = new ApolloClient({
  link: ApolloLink.from([errorLink, httpLink]),
  cache: new InMemoryCache(),
});

这样可以创建一个链接,链接中间件顺序可以影响错误处理的结果。

相关内容

热门资讯

透视新版!hhpoker真的假... 透视新版!hhpoker真的假的,newpoker怎么安装脚本,机巧教程(有挂方法)-哔哩哔哩new...
透视工具!wepoker怎么破... 透视工具!wepoker怎么破解游戏,wepoker高级辅助,阶段教程(了解有挂)-哔哩哔哩wepo...
透视教程!aapoker怎么选... 透视教程!aapoker怎么选牌,德州hhpoker脚本,演示教程(存在有挂)-哔哩哔哩1、点击下载...
透视辅助!德州局怎么透视,aa... 透视辅助!德州局怎么透视,aapoker ai插件,模板教程(有挂辅助)-哔哩哔哩1、很好的工具软件...
透视肯定!wpk透视是真的假的... 透视肯定!wpk透视是真的假的,德州局怎么透视,窍要教程(的确有挂)-哔哩哔哩1、wpk透视是真的假...
透视智能ai!wepokerp... 透视智能ai!wepokerplus脚本,wepoker怎么获得好牌,攻略教程(有挂技巧)-哔哩哔哩...
透视系统!德州局透视脚本下载安... 透视系统!德州局透视脚本下载安装最新版本,wpk安卓下载辅助,课程教程(有挂教学)-哔哩哔哩1、下载...
透视辅助!德普之星透视辅助软件... 透视辅助!德普之星透视辅助软件是真的吗,wepoker底牌透视,妙计教程(有挂方针)-哔哩哔哩1、这...
透视真的!hhpoker辅助靠... 透视真的!hhpoker辅助靠谱吗,pokerworld破解版下载,讲义教程(有挂方针)-哔哩哔哩1...
透视脚本!aapoker辅助工... 透视脚本!aapoker辅助工具安全吗,hhpoker视频巡查真的假的,练习教程(揭秘有挂)-哔哩哔...