Error Handling
This guide will help you handle and troubleshoot errors that may occur while using Dapi Flutter SDK.
When using Dapi Flutter SDK, any errors that occur will be passed to you as a DapiSdkException
object. This object contains detailed information about the error.
Parameter | Type | Description |
---|---|---|
type | String | Error type. |
message | String | Error message. |
operationID | String | Unique ID generated by Dapi to identify a specific operation. |
beneficiaryCoolDownPeriod | DapiValuePair | Beneficiary cool down period information (unit , value ) |
Bank Account Linking
To handle error events from the Connect Layer, you can listen to the onConnectionFailure
stream. This stream provides access to the ConnectFailureEvent
, which contains information about the error that occurred. You can use this information to handle the error appropriately.
Dapi.onConnectionFailure.listen((errorEvent) {
print(errorEvent.type);
print(errorEvent.error);
print(errorEvent.bankID);
});
Transfer
When calling the createTransfer
function, you may encounter errors such as invalid input, authentication issues, or network errors. To handle these errors, wrap your function call with a try-catch block, and catch the DapiSdkException
that may be thrown.
try {
CreateTransferResponse? result = await connection.createTransfer(account, beneficiary, 10, "Remark");
//No errors
print(result.accountID);
print(result.remark);
print(result.reference);
//...
} on DapiSdkException catch (error) {
print(error.type);
print(error.message);
print(error.operationID);
}
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.
try {
CreateTransferResponse? result = await connection.createTransfer(account, beneficiary, 10, "Remark");
//No errors
//...
} on DapiSdkException catch (error) {
print(error.beneficiaryCoolDownPeriod?.unit);
print(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 wrap your function call with a try-catch block, and catch the DapiSdkException
that may be thrown.
try {
DapiAccountsResponse accountsResponse = await connection.getAccounts();
//No errors
} on DapiSdkException catch (error) {
print(error.type);
print(error.message);
print(error.operationID);
}
Updated about 1 year ago