Some checks are pending
Build Release and Upload to TestFlight (iOS) / build (push) Waiting to run
Build Release and Upload to TestFlight (iOS) / testflight-upload (push) Blocked by required conditions
BuildReleaseApk / buildReleaseApk (push) Waiting to run
BuildReleaseApk / browserstack (push) Blocked by required conditions
54 lines
1.4 KiB
TypeScript
54 lines
1.4 KiB
TypeScript
import Bugsnag from '@bugsnag/react-native';
|
|
import { getUniqueId } from 'react-native-device-info';
|
|
|
|
import { BlueApp as BlueAppClass } from '../class/blue-app';
|
|
|
|
const BlueApp = BlueAppClass.getInstance();
|
|
|
|
/**
|
|
* in case Bugsnag was started, but user decided to opt out while using the app, we have this
|
|
* flag `userHasOptedOut` and we forbid logging in `onError` handler
|
|
* @type {boolean}
|
|
*/
|
|
let userHasOptedOut: boolean = false;
|
|
|
|
(async () => {
|
|
try {
|
|
// Don't try to start Bugsnag again as it's already initialized in native code.
|
|
// Configure it only when tracking is allowed.
|
|
const doNotTrack = await BlueApp.isDoNotTrackEnabled();
|
|
if (doNotTrack) {
|
|
userHasOptedOut = true;
|
|
return;
|
|
}
|
|
|
|
const uniqueID = await getUniqueId();
|
|
Bugsnag.setUser(uniqueID);
|
|
Bugsnag.addOnError(function () {
|
|
return !userHasOptedOut;
|
|
});
|
|
} catch (error) {
|
|
// Never let analytics setup crash the app.
|
|
console.error('Failed to initialize analytics:', error);
|
|
}
|
|
})();
|
|
|
|
const A = async (event: string) => {};
|
|
|
|
A.setOptOut = (value: boolean) => {
|
|
if (value) userHasOptedOut = true;
|
|
};
|
|
|
|
A.logError = (errorString: string) => {
|
|
console.error(errorString);
|
|
if (!userHasOptedOut) {
|
|
try {
|
|
Bugsnag.notify(new Error(String(errorString)));
|
|
} catch (error) {
|
|
console.error('Failed to report error to Bugsnag:', error);
|
|
}
|
|
}
|
|
};
|
|
|
|
export default A;
|