It is imperative that appropriate error handling is used when using RadiusCore via its API.
To enable appropriate error handling for calling applications when using RadiusCore from the command line, errors are raised directly to the calling procedure. This approach differs from that used when using RadiusCore from the user interface (Excel ribbon), where errors are handled within RadiusCore.
The downside of this approach is that, if errors are not appropriately handled in the calling application, RadiusCore’s run-time compile will break causing it to be unusable until Excel is restarted. To avoid this, developers need to ensure errors raised in procedures using the RadiusCore API are handled appropriately. A code sample is provided with a recommended approach to error handling when calling RadiusCore via the API.
RadiusCore's API will raise the following error codes:
' Generic Error Check Codes:
' 72010 / 8005194a / -2147149494 - RadiusCore not enabled.
' 72011 / 8005194b / -2147149493 - No Active Organisation.
' 72012 / 8005194c / -2147149492 - Insufficient permission.
' Procedure Specific Error Codes:
' 72020 / 80051954 / -2147149484 - Unexpected Error (this should never be seen!).
' 72021 / 80051955 / -2147149483 - Expected Error (i.e. refresh fails due to API error).
If you are using rc_Client to directly call the Xero/Practice Manager API, errors can be raised directly from this class.
' `rc_Authenticator` Error Codes:
' 11040 / 80042b20 / -2147210464 - Error with user authorisation.
' 11041 / 80042b21 / -2147210463 - Error retrieving access token.
' 11042 / 80042b22 / -2147210462 - Error retrieving tenants.
' 11043 / 80042b23 / -2147210461 - RadiusCore import/export error.
' 11044 / 80042b24 / -2147210460 - Connection ID does not exist in RadiusCore's database.
' 11045 / 80042b25 / -2147210459 - RadiusCore Connection not available.
'
' `rc_Client` Error Codes:
' 36010 / 80048caa / -2147185494 - Invalid request format.
' 36011 / 80048cab / -2147185493 - API error.
The following code snippet is a suggested manner for correctly handling errors raised by RadiusCore. It specifically handles RadiusCore errors differently to other errors that may occur in your code.
Public Sub radius_Sample()
' Set error handling at beginning of method.
On Error GoTo radius_ErrorHandling
' Call RadiusCore API. e.g.
RadiusCore.Refresh All:=True
' Do other things here...
Exit Sub
radius_ErrorHandling:
Select Case Err.Number - vbObjectError
Case 11040 to 110455, 36010 to 36011 ' These are the `rc_Client` error codes that can arise when directly calling Xero's API using RadiusCore.
MsgBox "An error occurred while calling Xero's API via RadiusCore:" & vbNewLine & _
Err.Description, vbExclamation + vbOKOnly, "My App Name"
Case 72010 to 72012 ' These are the `generic` RadiusCore error codes.
MsgBox Err.Description, vbExclamation + vbOKOnly, "My App Name"
Case 72020, 72021 ' These will be raised if an error occurs within a RadiusCore procedure.
MsgBox "A RadiusCore error occurred during my custom macro:" & vbNewLine & _
Err.Description & vbNewLine, vbCritical + vbOKOnly, "My App Name"
Case Else ' This will capture errors not raised by RadiusCore.
MsgBox "Non-RadiusCore error occurred here.", vbCritical + vbOKOnly, "My App Name"
End Select
End Sub