Reactjs 使用react-native处理Apollo错误
阿波罗错误处理有问题 基本上我需要全局错误处理。现在实际上我有全局错误处理,但它总是显示红色框 有没有办法将其更改为我自己的屏幕视图?(Reactjs 使用react-native处理Apollo错误,reactjs,react-native,apollo,apollo-client,Reactjs,React Native,Apollo,Apollo Client,阿波罗错误处理有问题 基本上我需要全局错误处理。现在实际上我有全局错误处理,但它总是显示红色框 有没有办法将其更改为我自己的屏幕视图?()还是什么?而不是红盒子 谢谢 阿波罗1.9.2版本 以下是我的全局错误处理程序: 我也有同样的问题,并解决了apollo-linkerror包中提到的错误处理程序 参考网址: const handleErrors = ({ response }, next) => { const res = response.clone() if (!res.o
)还是什么?而不是红盒子
谢谢
阿波罗1.9.2版本
以下是我的全局错误处理程序:
我也有同样的问题,并解决了
apollo-linkerror
包中提到的错误处理程序
参考网址:
const handleErrors = ({ response }, next) => {
const res = response.clone()
if (!res.ok) {
if (res.status === 500) {
throw new Error('Error')
}
return next();
}
}
networkInterface.useAfter([{
applyAfterware: handleErrors,
}]);
const client = new ApolloClient({
networkInterface,
});
import React, {Component} from 'react';
import {AsyncStorage, Alert} from 'react-native';
import {ApolloClient} from 'apollo-client';
import {InMemoryCache} from 'apollo-cache-inmemory';
import {HttpLink} from 'apollo-link-http';
import {setContext} from 'apollo-link-context';
import { onError } from "apollo-link-error";
const httpLink = new HttpLink({uri: NetworkInterFace});
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 authLink = setContext(async (req, {headers}) => {
let userDetails = await AsyncStorage.getItem('userToken');
userDetails = JSON.parse(userDetails);
if (userDetails === null) {
return {
...headers,
headers: {
authorization: '',
},
};
} else {
return {
...headers,
headers: {
authorization: userDetails.token,
},
};
}
});
const link = errorLink.concat(authLink.concat(httpLink));
export const client = new ApolloClient({
link,
cache: new InMemoryCache(),
});