Quantcast
Channel: Active questions tagged react-native+typescript - Stack Overflow
Viewing all articles
Browse latest Browse all 6287

How to handle mutation GraphQL error instead of Apollo onError()

$
0
0

Server side, I am throwing a 403 Forbidden, to manage access to an API call.

To catch the GraphQL error for a mutation, I've tried the following: (method #1 is working when catching errors for useQuery())

const [m, { error }] = useMutation(MY_MUTATION);if(error) {    console.error('Error return #1');}try {  await m({    variables,    onError: (e: ApolloError) => {       console.error('Error return #2');    }  }).catch(e) {     console.error('Error return #3');  };} catch (e) {    console.error('Error return #4');}

Instead, from my Apollo onError(), the following GraphQL errors are returned and the execution stops. It does not go into any of my mutation error handling attempts:

graphQLErrors:, Array [  Object {"extensions": Object {"code": "FORBIDDEN","response": Object {"error": "Forbidden","message": "Access is denied.","statusCode": 403,      },    },"message": "Access is denied.",  },]

If a similar GraphQL error is returned from useQuery(), it shows it using:

const { data, error, loading } = useQuery( MY_QUERY );if(error) {    console.error('Error return #1');}

Viewing all articles
Browse latest Browse all 6287

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>