我遇到了apollo-link-error问题,我能够记录该错误,但是我想显示一个带有错误的模式或将其显示在另一页上,是否有可能在不处理每个请求的情况下出现错误?
反应,Apollo客户端/服务器,https://github.com/kriasoft/react-starter-kit/tree/feature/apollo-pure
onError(({ graphQLErrors, networkError, response }) => {
console.log(graphQLErrors);
if (graphQLErrors) {
graphQLErrors.map(({message, locations, path, extensions}) => {
console.warn(
`[GraphQL error]: Message: ${message}, Location: ${locations}, Path: ${path}`,
);
if (extensions && extensions.exception && (extensions.exception.code === 16 || extensions.code === 'UNAUTHENTICATED')) {
// UNAUTHENTICATED
response.errors = null;
history.push('/login');
}
});
}
if (networkError) console.warn(`[Network error]: ${networkError}`);
}),
现在,如果在渲染时发生错误,我可以捕获带有错误边界的错误,并以一种漂亮的方式展示它。但是当渲染后发生错误时,它将被忽略