Skip to content

Error handling

Some errors have a class HolyheldSDKError. The most helpful property of these errors is code. You can compare the code with the values in the HolyheldSDKErrorCode.

typescript
import { HolyheldSDKError, HolyheldSDKErrorCode } from '@holyheld/sdk';

const holyheldSDK = new HolyheldSDK({
  apiKey: process.env.HOLYHELD_SDK_API_KEY,
})

try {
  await holyheldSDK.evm.offRamp.topup(/* ... */);
} catch (error) {
  if (
    error instanceof HolyheldSDKError &&
    (error.code === HolyheldSDKErrorCode.UserRejectedTransaction ||
      error.code === HolyheldSDKErrorCode.UserRejectedSignature)
  ) {
    // it's OK
  } else {
    // it's NOT OK
  }
}

Types:

typescript
enum HolyheldSDKErrorCode {
  NotInitialized = 'HSDK_NI', // SDK is not initialized
  FailedInitialization = 'HSDK_FI', // cannot initialize SDK
  UnsupportedNetwork = 'HSDK_UN', // wallet active network is not supported by SDK
  InvalidTopUpAmount = 'HSDK_ITUA', // amount does not meet minimum or maximum allowed criteria
  InvalidOnRampAmount = 'HSDK_IORA', // amount does not meet minimum or maximum allowed criteria
  UnexpectedWalletNetwork = 'HSDK_UWN', // wallet active network is different from the selected network
  UserRejectedSignature = 'HSDK_RS', // user rejected the signature
  UserRejectedTransaction = 'HSDK_RT', // user rejected transaction
  FailedSettings = 'HSDK_FS', // cannot get settings
  FailedTagInfo = 'HSDK_FTI', // cannot get $holytag info
  FailedAddressInfo = 'HSDK_FAI', // cannot get address info
  FailedWalletBalances = 'HSDK_FWB', // cannot get wallet balance
  FailedConversion = 'HSDK_FC', // cannot estimate EUR to TOKEN, or TOKEN to EUR
  FailedTopUp = 'HSDK_FTU', // cannot complete top up
  FailedCreateOnRampRequest = 'HSDK_FCOR', // cannot create onramp request
  FailedOnRampRequest = 'HSDK_FOR', // fail execute onramp request with reason (for example not enough balance)
  FailedWatchOnRampRequestTimeout = 'HSDK_FwORT', // watch request timeout
  FailedWatchOnRampRequest = 'HSDK_FWORR', // fail to watch request status
  FailedConvertOnRampAmount = 'HSDK_FCORA', // cannot convert (estimate) EUR to TOKEN, or TOKEN to EUR
  FailedOnRampEstimation = 'HSDK_FORE', // cannot estimate the network fee amount and the final token amount
}

Error recovery categories

Not all errors are equal. Some are safe to retry immediately; others require user action; others are permanent failures.

CategoryError codesRecovery
Retry automaticallyHSDK_FS, HSDK_FTI, HSDK_FAI, HSDK_FWB, HSDK_FC, HSDK_FCOR, HSDK_FWORR, HSDK_FCORA, HSDK_FORENetwork or transient failures — retry with exponential backoff
Prompt the user to actHSDK_RS, HSDK_RT, HSDK_UWN, HSDK_UN, HSDK_ITUA, HSDK_IORA, HSDK_FORUser must take an action (switch network, adjust amount, confirm transaction)
Check before retryingHSDK_FTU, HSDK_FwORTInspect state before retrying — the operation may have partially succeeded
Fix configurationHSDK_NI, HSDK_FISDK is not correctly initialised — fix setup, then retry

Error code reference

Error codeConstantCauseRecommended action
HSDK_NINotInitializedSDK method called before init() completedCall await holyheldSDK.init() before any other SDK method
HSDK_FIFailedInitializationinit() failed — invalid SDK API key or network unreachableCheck your SDK API key; retry init() after a short delay
HSDK_UNUnsupportedNetworkThe wallet's current chain is not supported by the SDKPrompt the user to switch to a supported network
HSDK_ITUAInvalidTopUpAmountToken amount is below the minimum or above the maximum EUR limitCheck getServerSettings() for current limits; adjust the amount
HSDK_IORAInvalidOnRampAmountEUR amount is below the minimum or above the maximum limitCheck getServerSettings() for current limits; adjust the amount
HSDK_UWNUnexpectedWalletNetworkWallet is on a different chain than tokenNetworkPrompt the user to switch their wallet to the correct network before calling topup
HSDK_RSUserRejectedSignatureUser dismissed the signature request in their walletShow a dismissible error — no retry needed unless the user wants to try again
HSDK_RTUserRejectedTransactionUser dismissed the transaction confirmation in their walletSame as above — no retry needed unless the user chooses to
HSDK_FSFailedSettingsgetServerSettings() network request failedRetry with exponential backoff; show "temporarily unavailable" if retries exhaust
HSDK_FTIFailedTagInfogetTagInfo() network request failedRetry; if persistent, the holytag may not exist
HSDK_FAIFailedAddressInfovalidateAddress() network request failedRetry; if persistent, the address may not be eligible
HSDK_FWBFailedWalletBalancesgetWalletBalances() network request failedRetry; check network connectivity
HSDK_FCFailedConversionconvertTokenToEUR() or convertEURToToken() failedRetry; if persistent, the token may not be supported on the selected network
HSDK_FTUFailedTopUptopup() failed to completeCheck error.message for detail; common causes: insufficient balance, unsupported token, network congestion
HSDK_FCORFailedCreateOnRampRequestrequestOnRamp() could not create the requestRetry; if persistent, check that the wallet address is eligible
HSDK_FORFailedOnRampRequestOn-ramp request rejected — e.g. insufficient card balanceShow the error message to the user; they may need to top up their Holyheld card
HSDK_FwORTFailedWatchOnRampRequestTimeoutwatchRequestId() timed out before user confirmedThe request may still be pending in the Holyheld app; inform the user and allow them to retry
HSDK_FWORRFailedWatchOnRampRequestwatchRequestId() could not retrieve request statusRetry watchRequestId() with the same requestUid; the underlying request is still valid
HSDK_FCORAFailedConvertOnRampAmountOn-ramp EUR/token conversion failedRetry; if persistent, check the selected token and network
HSDK_FOREFailedOnRampEstimationOn-ramp fee and expected amount estimation failedRetry; if persistent, show a temporary estimation failure message