RTK query error handling, global error handling without notifing subscribed components #2094
Unanswered
andreazanti
asked this question in
Q&A
Replies: 1 comment 1 reply
-
Since the error could pretty much be "whatever", you will have to check on the type of error in your component either way. We don't really make any distinction between global or non-global errors. |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hi everyone!
First of all i want to thank the creator of this fantastic library, i love it!
I explain the problem and use case:
i've created a custom fetchBaseQuery like explained in this page, because i'm developing a mobile application and i need to implement ssl pinning and react native base fetch don't do it.
Now when i receive an error from my API i write some native code to differentiate if the error is an ssl error or of another type, in particular if it is an SSL error i want to open an alert and all the components subscribed to this endpoint should not handle the error in no way.
Current solution:
`
// Error type returned when there is an error from fetch inside customFetchBasequery
export type Error = {
status: number | undefined;
data?: any;
type: "ssl" | .....others;
};
// Exposed function callable from components with error object from hooks to check if error is ssl
const handledErrorTypes = ["ssl"];
export function isGlobalError(error: any): boolean {
return handledErrorTypes.includes(error.type);
}
// Example of component
useEffect(() => {
if (
apiResponse.isError &&
!isGlobalError(apiResponse.error)
) {
// DO SOME STUFF ONLY IF NOT GLOBAL ERROR
}
}, [apiResponse]);
`
I don't like this solution because i have to check everytime if error is global or not.
Any ideas?
It could be great if the baseQuery could return undefined when the components should not be notified of the error.
Thanks in advance
Beta Was this translation helpful? Give feedback.
All reactions