Advertisement
Guest User

Untitled

a guest
Oct 15th, 2019
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.94 KB | None | 0 0
  1. const errorLink = onError(
  2. ({ graphQLErrors, networkError, operation, forward }) => {
  3. if (graphQLErrors)
  4. graphQLErrors.map(({ message, extensions }) => {
  5. switch (extensions.code) {
  6. case "invalid-jwt":
  7. // refetch the jwt
  8. const oldHeaders = operation.getContext().headers;
  9. const token = getAccessToken();
  10. operation.setContext({
  11. headers: {
  12. ...oldHeaders,
  13. authorization: `Bearer ${token}`
  14. }
  15. });
  16. // retry the request, returning the new observable
  17. return forward(operation);
  18. break;
  19. default:
  20. // default case
  21. console.log(extensions.code);
  22. }
  23. });
  24. if (networkError) {
  25. console.log(`[Network error]: ${networkError}`);
  26. props.history.push("/network-error");
  27. }
  28. }
  29. );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement