Skip to content

Instantly share code, notes, and snippets.

@acro5piano
Created November 26, 2022 16:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save acro5piano/fc23532a94ac2cd7366b4041032ef759 to your computer and use it in GitHub Desktop.
Save acro5piano/fc23532a94ac2cd7366b4041032ef759 to your computer and use it in GitHub Desktop.
URQL automatic error handling toaster
import { Exchange } from 'urql';
import { pipe, tap } from 'wonka';
import { toast } from 'react-hot-toast';
export const errorExchange: Exchange =
({ forward }) =>
(ops$) =>
pipe(
forward(ops$),
tap(({ error }) => {
if (error) {
toast.error(error.message.replace('[GraphQL]', ''), {
id: 'graphql-error',
});
}
}),
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment