react-native-fabric
react-native-fabric copied to clipboard
Can't record an error with Crashlytics.recordError()
So that pretty much it is. Crashlytics.crash() does well and everything gets recorded as expected, but not in case with recordError(error) method.
My code snipped is below and it's needless to say that componentDidCatch() method is called as well.
componentDidCatch(error, info) {
Crashlytics.recordError(error);
}
What could be the reason of such behavior? Any help is appreciated.
recordError only works on iOS and the reverse is true of logException on Android. Are you on Android? I've added code in my exception handles to check Platform.OS before calling a method but its less than ideal.
@willderness no, I use iOS device and emulator for testing and still can't make it work. How is that even possible? The very first and basic function doesn't work for some reason. Thanks for your reply.
@igorarkhipenko after having the same issue myself i realized recordError only works on an actual device and does not work via the emulator. Hope this helps
I created a helper for logging errors feel free to use it
import { Crashlytics } from "react-native-fabric";
import { Platform } from "react-native";
export default logError = ( err ) => {
if ( Platform.OS === "ios" ) {
Crashlytics.recordError( err );
} else {
Crashlytics.logException( err );
}
console.log( err );
};
console.log should help you in the emulator
@shyaniv7 could you please elaborate on what environments you manage to makes it work?
As stated in the code this will log an error to crashlytics on both android and iOS using a single logError function.
@shyaniv7 I mean configuration like are you on debug mode, simulator, or device. Something like that
We actually have environment variables where we are able to know what environment we are running, what device, api version, app version and more information and whenever we use the logError we concatenate those information onto the error message before logging it.
We wrote a fetch wrapper that makes our api requests and handles any caught errors using logError