ApolloErrorHandler.ts 897 B

12345678910111213141516171819202122232425262728
  1. import {
  2. CombinedGraphQLErrors,
  3. CombinedProtocolErrors,
  4. LocalStateError,
  5. ServerError,
  6. ServerParseError,
  7. UnconventionalError,
  8. } from "@apollo/client/errors";
  9. // about apollo client error handle https://www.apollographql.com/docs/react/data/error-handling
  10. // Comprehensive error handling example.
  11. function handleError(error: unknown) {
  12. if (CombinedGraphQLErrors.is(error)) {
  13. // Handle GraphQL errors
  14. } else if (CombinedProtocolErrors.is(error)) {
  15. // Handle multipart subscription protocol errors
  16. } else if (LocalStateError.is(error)) {
  17. // Handle errors thrown by the `LocalState` class
  18. } else if (ServerError.is(error)) {
  19. // Handle server HTTP errors
  20. } else if (ServerParseError.is(error)) {
  21. // Handle JSON parse errors
  22. } else if (UnconventionalError.is(error)) {
  23. // Handle errors thrown by irregular types
  24. } else {
  25. // Handle other errors
  26. }
  27. }