Skip to main content
Not yet released. The lending module described here ships with @trusset/sdk 0.4.0, which is not on npm yet: npm install @trusset/sdk installs 0.1.0, which carries the customers module only. Until 0.4.0 is published, call the Lending API directly.
This page is for the engineer writing the catch blocks around lending calls. After reading it you will know which errors stop a write before anything is signed, which mean a transaction is on chain but not recorded, and which are worth retrying. The lending module uses the error classes every SDK module shares: TrussetError and its subclasses ValidationError, AuthError, NetworkError and ConfirmationError. Each carries code, statusCode, requestId, details, data and retryAfter. See Error handling for the class hierarchy and the codes that apply to every module.

Know what was sent before you act

The first question for any failed write is whether a transaction went out. The answer decides the next step.
Never repeat a write after a ConfirmationError. A second call prepares a second plan, and signing it moves funds or collateral again. Finish the first one with { txHash }. See finish a write that stopped halfway.

Errors the SDK raises itself

These come from checks the SDK runs before or while it signs. A status of 0 means the error never came from the API. ConfirmationError also carries transactions, one entry per step with functionName, txHash, optional and error, plus txHash, the hash to confirm, and failure, the underlying error.

API codes every area shares

Area pages list the codes of their own routes. These come back from every area. A 503 from a lending route means a chain read or a record could not be read just then. It is never a verdict about the market, the loan or the wallet. Treat it as unknown and retry, not as a refusal.

Retry behavior

The SDK retries by request kind. A build or an off-chain write is never repeated after an ambiguous failure, because the first attempt may already have taken effect. On a 429 the SDK waits as long as Retry-After says, at most 60 seconds. Other retries back off 1, 2 and 4 seconds, capped at 10. maxRetries on the client caps the attempts, and 0 turns retries off. The confirms sent once belong to bots.deploy, liquidations.withdrawCollateralForSale, liquidations.reportPartialSale and liquidations.handleTimeout. The API does not record them idempotently. When one fails ambiguously, read the bot or the liquidation before you confirm again.

Catch a lending write

Order the branches from most specific to least. ConfirmationError extends TrussetError, so test it first.
An error the API returns may carry extra fields beside code and message, such as candidates on an unknown market or the role a refusal names. They land in err.data.