Created
November 26, 2022 16:37
-
-
Save acro5piano/fc23532a94ac2cd7366b4041032ef759 to your computer and use it in GitHub Desktop.
URQL automatic error handling toaster
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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