Error Handling

This guide will help you handle and troubleshoot errors that may occur while using Dapi Flutter SDK.

When using Dapi React Native SDK, any errors that occur will be passed to you as a DapiError object. This object contains detailed information about the error.

ParameterTypeDescription
typeStringError type.
messageStringError message.
operationIDStringUnique ID generated by Dapi to identify a specific operation.
beneficiaryCoolDownPeriodObjectBeneficiary cool down period information (unit, value)

Bank Account Linking

Using the NativeEventEmitter to listen for events in the Dapi SDK, you can handle connect failures by listening for the 'EventConnectFailure' event. This event provides access to the errorResult object, which contains information about the error that occurred.

const {DapiConnectManager} = NativeModules;
const dapiConnectManagerEmitter = new NativeEventEmitter(DapiConnectManager);
//....

dapiConnectManagerEmitter.addListener(
  'EventConnectFailure',
  errorResult => {
    console.log(errorResult.bankID);
    console.log(errorResult.error);
  }
);

Transfer

When calling the createTransfer function, you may encounter errors such as invalid input, authentication issues, or network errors. To handle these errors, use the catch method to catch any errors that may occur.

connection?.createTransfer(account, beneficiary, 100, 'Remark')
  .then(response => {
    console.log(`Transfer success ${response}`);
  })
  .catch(err => {
    let error = err as DapiError;
    console.log(
      `Transfer failed with error
        ${error.type} 
        ${error.message}
        ${error.operationID}
        ${error.account} 
        ${error.beneficiaryCoolDownPeriod!.unit}
        ${error.beneficiaryCoolDownPeriod!.value}`
    );

Beneficiary Cool Down

Some banks do not allow immediate transfers to a newly added beneficiary. Beneficiary Cooldown time shows how long the user needs to wait before they can make a transfer to a newly added beneficiary.

You can know the potential cooldown value ahead of time by using Get Account Metadata endpoint. The value varies bank to bank.

If you encounter a BENEFICIARY_COOL_DOWN_PERIOD error, you will receive an error object with error type set to BENEFICIARY_COOL_DOWN_PERIOD and the object will contain information about the beneficiary cooldown period beneficiaryCoolDownPeriod, including the unit and value, which you can access to handle the error appropriately.

connection?.createTransfer(account, beneficiary, 100, 'Remark')
  .then(response => {
    console.log(`Transfer success ${response}`);
  })
  .catch(err => {
    let error = err as DapiError;
    console.log(
      `Transfer failed
        ${error.beneficiaryCoolDownPeriod!.unit}
        ${error.beneficiaryCoolDownPeriod!.value}`
    );

If the user attempts to retry the request before the beneficiary cooldown period is complete, the error.type will still be BENEFICIARY_COOL_DOWN_PERIOD. However, in this case, the error.beneficiaryCoolDownPeriod value will be null.

Other APIs

When calling any Dapi API, it's important to handle any errors that may occur. To do this, you should use the catch method to catch any errors that may occur.

await connection?.getAccounts().then(response => {
  //No errors
}).catch(err => {
  let error = err as DapiError;
  console.log(error.type, error.message);
  //....
});