terveystalo / react-native-piwik-pro-sdk

React Native wrapper for Piwik Pro SDK
https://www.npmjs.com/package/react-native-piwik-pro-sdk
MIT License
2 stars 2 forks source link

fix: error handling #29

Closed aeirola closed 3 years ago

aeirola commented 3 years ago

Fixes Android app crashing when the the tracker is not initialised.

The issue was that the code was throwing an Error class, but only catching Exception class throwables, which is not a superclass of Error. This resulted in the following kind of errors when attempting to track events before initialisation was completed:

Caused by java.lang.Error: Tracker is not initialized
       at com.reactnativepiwikprosdk.PiwikProSdkModule.trackEvent(PiwikProSdkModule.java:79)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.facebook.react.bridge.JavaMethodWrapper.invoke(JavaMethodWrapper.java:149)

Here we fix the issue by changing the type of class thrown when the tracker has not been initialised.

aeirola commented 3 years ago

Yes, that is a valid concern. Looking at the code for the react native Promise.reject we see that it accepts any Throwable, of which both Error and Exception are subclassed.