Replies: 2 comments 3 replies
-
This is an idea for a quality of life improvement. It doesn't really add anything to functionality or fix anything that is broken. Just looking for opinions on the matter. |
Beta Was this translation helpful? Give feedback.
3 replies
-
Created an util function hope it helps import { ReactNativeFirebase } from "@react-native-firebase/app"; /**
* Type guard to check if the error is a NativeFirebaseError
* @param error - The error object to check
* @returns {boolean} - True if the error is a NativeFirebaseError
*/
export function isNativeFirebaseError(
error: any
): error is ReactNativeFirebase.NativeFirebaseError {
return error && error.code && error.message;
} |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I would like to be able to use the React Native Firebase error types to switch between different error handling in my TypeScript code.
Currently, the error types in the RNF project are declared as interfaces. As such, I cannot use the
instanceof
operator to switch between handling because interfaces are only useful to the TypeScript compiler and are not transpiled to JavaScript for use byinstanceof
, nor can I use the notion of typed systems as intended to definitively look up the properties of an error.For my use case, I would specifically like to know the error's
code
field value. I can, of course, do something like:However, I feel that this sidesteps typed systems entirely.
I think it would make for cleaner code to be able to handle it like:
The code might be a bit more obtuse, but it makes use of the typed system more elegantly. Additionally, it can still be handled by the first example, given that
e
is ofany
type when caught and could potentially have acode
field.I think the only downside is that it would use slightly more memory given that the errors would have to be instances of
ReactNativeFirebase.NativeFirebaseError
extendingError
, rather than just instances ofError
with additional fields.Aside
On a similar note about RNF errors, I do wonder why
ReactNativeFirebase.NativeFirebaseError
declares areadonly message: string
field when itextends Error
which already has amessage: string
field. Though not specificallyreadonly
, if a developer is changing an Error's message in their code then why stop them?Beta Was this translation helpful? Give feedback.
All reactions