React Native

Implement logging and error handling for React Native.

Add logging

To add logging, perform the following steps:

  1. Register for events callbacks.
const registerEventsCallback = async () => {
   const eventEmitter =
       Platform.OS === 'ios'
       ? new NativeEventEmitter(NativeModules.FordefiSdk)
       : new NativeEventEmitter(NativeModules.FordefiSdkModule);
  1. Add an events listener to the event type LogEvent:
eventEmitter.addListener('LogEvent', (event) => {
    console.log(`${event.logLevel}: ${event.logMessage}`);
 });
  1. After the Fordefi SDK is initialized, call the setLogger method with one of the desired LogLevels (type LogLevel = 'verbose' | 'info' | 'warning' | 'error'):
await setLogger("info");

Add error handling

To add error handling, perform the following steps:

  1. Register events callback.
const registerEventsCallback = async () => {
   const eventEmitter =
      Platform.OS === 'ios'
      ? new NativeEventEmitter(NativeModules.FordefiSdk)
      : new NativeEventEmitter(NativeModules.FordefiSdkModule);
  1. Add events listener to event type ErrorEvent:
const eventEmitter =  Platform.OS === 'ios' ? new NativeEventEmitter(NativeModules.FordefiSdk): new NativeEventEmitter(NativeModules.FordefiSdkModule);
eventEmitter.addListener('ErrorEvent', event => {
    console.log(`Error ${event.errorCode}: ${event.errorMessage}`);
});
  1. After the Fordefi SDK is initialized, call the setErrorHandler method:
await setErrorHandler();