Changelog

Error handling

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

When using the Dapi Web SDK, the response to any request contains the field status. The response when a request fails (status !== "done" ) shall contain:

ParameterTypeDescription
typeStringError type.
msgStringError message.
operationIDStringUnique ID generated by Dapi to identify a specific operation.
coolDownPeriodDapiBeneficiaryCoolDownPeriodBeneficiary cool down period information:
{ value, unit }

Bank Account Linking

To handle responses from the Connect Layer, define the methods onSuccessfulLogin, onFailedLogin, and onExit. Which are called depending on the result of the connection attempt. In the case of an error while linking a bank account, the callback onFailedLogin will be called with the error as its only argument.

const otherConfigParams = {
  // rest of configuration params
};
var handler = Dapi.create({
  ...otherConfigParams,
  onSuccessfulLogin: function (bankAccount) {
    //handle success
  },
  onFailedLogin: function (err) {
    if (err) {
      //handle error
    } else {
      console.log("Unknown error");
    }
  },
  onExit: function () {
    // Fired whenever the connect layer is dismissed 
    // regardless of the connection status
    console.log("User exited the connect layer");
  },
});

Data APIs

Errors with API calls on a linked bank account can be detected via the field status in the response. The field status will have the value "done" when the API call is successful, and the value "failed" when there is an error.

ba.data.getIdentity()
  .then(identityResponse => {
    if (identityResponse.status === "done") {
      console.dir(identityResponse);
    } else {
      console.error("API Responded with an error");
      console.dir(identityResponse);
    }
  })
  .catch(error => {
    console.dir(error); //Client-side error
  });

Payment APIs

Similar to data APIs, errors with API calls on a bank account can be detected via the field status in the response. The field status will have the value "done" when the API call is successful, and the value "failed" when there is an error.

const transfer = {
  //transfer params
};
ba.payment.transferAutoflow(transfer)
  .then(transferResponse => {
    if (transferResponse.status === "done") {
      console.dir(transferResponse);
    } else {
      console.error("API Responded with an error");
      console.dir(transferResponse);
    }
  })
  .catch(error => {
    console.dir(error); //Client-side error
  });

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 response object with field type set to BENEFICIARY_COOL_DOWN_PERIOD and the object will contain information about the beneficiary cooldown period coolDownPeriod, including the unit and value, which you can access to handle the error appropriately.

const transfer = {
  //transfer params
};
ba.payment.transferAutoflow(transfer)
  .then(transferResponse => {
    if (transferResponse.status === "done") {
      console.dir(transferResponse);
    } else {
      if (!transferResponse.type) {
        //unknown error
      }
      switch (transferResponse.type){
        //...
        case "BENEFICIARY_COOL_DOWN_PERIOD": {
          const coolDownPeriod = transferResponse.coolDownPeriod;
          let unit, value;
          if (!!coolDownPeriod) {
            unit = coolDownPeriod?.unit;
            value = coolDownPeriod?.value;
            //do something with coolDownPeriod;
          }
        }
        //...
      }
    }
  })
  .catch(error => {
    console.dir(error); //Client-side error
  });

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

Error codes

The field type will have a value corresponding to a specific error code. The error codes from the Dapi APIs can be found here. On top of these errors, the SDK has an extra error when the user dismisses the MFA modal without inputing the required answers. This error has type equal to "DIALOGUE_BOX_CLOSED".