RebelfiError Class
All API errors are thrown asRebelfiError instances with structured information:
import { RebelfiError, ErrorCode } from '@rebelfi/sdk';
try {
await client.operations.supply(request);
} catch (error) {
if (error instanceof RebelfiError) {
console.error('Message:', error.message);
console.error('Status:', error.statusCode);
console.error('Code:', error.code);
console.error('Details:', error.details);
}
}
Properties
| Property | Type | Description |
|---|---|---|
message | string | Human-readable error message |
statusCode | number | HTTP status code |
code | ErrorCode | Machine-readable error code |
details | object | Additional error context |
Checking Error Type
Use the.is() method to check for specific errors:
if (error instanceof RebelfiError) {
if (error.is(ErrorCode.INSUFFICIENT_BALANCE)) {
// Show "insufficient funds" message to user
} else if (error.is(ErrorCode.OPERATION_EXPIRED)) {
// The five-minute signing deadline passed: plan a new operation
}
}
Error Codes
Validation Errors (4xx)
| Code | Description | Recommended Action |
|---|---|---|
INVALID_AMOUNT | Amount is zero, negative, or malformed | Validate amount before calling |
INVALID_ADDRESS | Wallet address format is invalid | Validate address format |
INVALID_TOKEN | Token address not recognized | Use address from strategy |
if (error.is(ErrorCode.INVALID_AMOUNT)) {
// Show validation error to user
showError('Please enter a valid amount');
}
Business Logic Errors (4xx)
| Code | Description | Recommended Action |
|---|---|---|
INSUFFICIENT_BALANCE | Wallet balance too low for operation | Show balance, suggest lower amount |
STRATEGY_NOT_ACTIVE | Strategy is paused or deprecated | Refresh venues, pick another |
ALLOCATION_NOT_FOUND | No position exists at this venue | Check allocations first |
OPERATION_EXPIRED | The operation passed its five-minute signing deadline (expiresAt); getUnsignedTransactions() and submitSigned() refuse it and nothing was broadcast | Plan a new operation once operations.get() shows it has left AWAITING_SIGNATURE. If a submitSigned() returned resubmitSameTransaction: true, or you reported a hash, it stays live until RebelFi sees whether that transaction landed, and a plan meanwhile gets OPERATION_IN_PROGRESS |
OPERATION_ALREADY_SUBMITTED | submitSigned(). 409: another signed transaction for this transaction is in flight or recorded; nothing was broadcast. 400: the broadcast failed | 409: resubmit the first signed transaction, or check the operation status. 400: read details.resubmitSameTransaction: true, resubmit the same signed transaction (don’t sign again); false, sign again |
TRANSACTION_MISMATCH | The signed transaction or reported hash is not the transaction planned for the operation; nothing was broadcast or recorded | Sign the transactions returned for this operation, unchanged apart from nonce and gas (EVM) or compute budget (Solana) |
TOKEN_MISMATCH | Token doesn’t match strategy | Use tokenAddress from strategy |
INVALID_OPERATION_STATUS | cancel(): a transaction was already submitted, or the operation is confirmed | Check operation status first |
OPERATION_IN_PROGRESS | The wallet has a live operation this API key may not replace: awaiting approval, under way, another API key’s or user’s plan awaiting signature, or a plan (yours included) whose submitted or reported transaction may still land | Wait for it: a plan usually clears shortly after its expiresAt; if expiresAt has passed, retry in a few seconds. An operation whose transaction may still land is held until RebelFi sees whether it landed. Or cancel it by details.operationId. Your own key’s plan with nothing submitted or reported is replaced instead |
WALLET_NOT_VERIFIED | The wallet is watch-only (403): your organization hasn’t proven control of its address | Prove control with wallets.challenge() and wallets.verify(), then retry |
switch (error.code) {
case ErrorCode.INSUFFICIENT_BALANCE:
const balance = error.details?.available;
showError(`Insufficient balance. Available: ${balance}`);
break;
case ErrorCode.STRATEGY_NOT_ACTIVE:
// Refresh and show available strategies
await refreshStrategies();
showError('This strategy is no longer available');
break;
case ErrorCode.OPERATION_EXPIRED:
// The signing deadline passed: plan again once operations.get() shows it left AWAITING_SIGNATURE
return await retryOperation();
case ErrorCode.OPERATION_IN_PROGRESS:
// Another live operation holds the wallet — wait or cancel it
const { operationId, status, expiresAt } = error.details as { operationId: number; walletId: number; status: string; expiresAt?: string };
showError(
`Operation ${operationId} (${status}) holds this wallet` +
(expiresAt ? ` until ${expiresAt}` : '') + '. Please try again later.'
);
break;
}
Proof of Control Errors
Returned bywallets.register({ proof }) and wallets.verify(). See Request Ownership Challenge.
| Code | HTTP | Description | Recommended Action |
|---|---|---|---|
CHALLENGE_EXPIRED | 410 | The challenge passed its expiresAt | Request a new challenge and sign it |
CHALLENGE_USED | 409 | The challenge was already used | Request a new challenge and sign it |
CHALLENGE_MISMATCH | 400 | Unknown challenge, or issued for another address or chain | Request a challenge for this wallet’s address and chain |
INVALID_SIGNATURE | 400 | Not the address’s signature of the challenge message. The challenge is used up | Check the signing encoding (Solana base58, EVM 0x hex) and sign a new challenge with the wallet that holds the address |
ADDRESS_NOT_CLAIMABLE | 409 | Another organization has already proven control of the address | Contact support if you believe you control it |
503
(error.code is INTERNAL_ERROR). Nothing was written and the challenge stays usable: retry with the same proof.
try {
await client.operations.supply(params);
} catch (error) {
if (error instanceof RebelfiError && error.is(ErrorCode.WALLET_NOT_VERIFIED)) {
const { challengeId, message } = await client.wallets.challenge({ walletAddress, blockchain: 'solana' });
const signature = await signWithWallet(message); // base58 on Solana, 0x hex on EVM
await client.wallets.verify(walletId, { challengeId, signature });
await client.operations.supply(params);
}
}
Client Account Errors
For organizations that open client accounts.| Code | HTTP | Description | Recommended Action |
|---|---|---|---|
CLIENT_ACCOUNTS_NOT_ENABLED | 403 | Your organization doesn’t open client accounts | Contact RebelFi to enable them, or leave out accountId |
ACCOUNT_NOT_FOUND | 404 | No client account with this ID in your organization | Check the accountId you stored from accounts.create() |
ACCOUNT_REFERENCE_CONFLICT | 409 | The reference already names an account with another contact email | Use the existing account, or another reference |
CONTACT_EMAIL_UNAVAILABLE | 409 | The contact email already belongs to a RebelFi user or another client account | Ask the client for another contact address |
ACCOUNT_ALREADY_ACTIVE | 409 | Resend refused: the account is no longer pending | Nothing to resend |
ACTIVATION_LINK_USED | 409 | Resend refused: the contact already set a password with the link | Ask the contact to sign in to the portal to finish |
USER_ID_NOT_ALLOWED | 400 | userId sent on register or update | Send accountId on register; userId is set from the account |
WALLET_LINKED_TO_ANOTHER_ACCOUNT | 409 | The wallet is already linked to another account | Check error.details.linkedAccountId |
CLIENT_ACCOUNT_REQUIRED | 403 | Supply refused: the wallet is linked to no account | Register the wallet with its accountId, then retry |
CLIENT_ACCOUNT_NOT_ACTIVE | 403 | Supply refused: the account is pending activation or suspended | Wait for the client to activate (accounts.get()), or contact RebelFi if suspended. Unwind still works |
if (error.is(ErrorCode.CLIENT_ACCOUNT_NOT_ACTIVE)) {
const { accountId, status } = error.details as { orgWalletId: number; accountId: number; status: string };
showError(status === 'PENDING_ACTIVATION'
? 'Your client has not activated its account yet'
: 'This client account is suspended');
}
Resource Errors (404)
| Code | Description | Recommended Action |
|---|---|---|
VENUE_NOT_FOUND | Venue ID doesn’t exist | Refresh venue list |
STRATEGY_NOT_FOUND | Strategy ID doesn’t exist | Refresh venue list |
OPERATION_NOT_FOUND | Operation ID doesn’t exist | May have been cleaned up |
TRANSACTION_NOT_FOUND | Transaction ID doesn’t exist | Check operation status |
WALLET_NOT_FOUND | Wallet not registered | Register the wallet first via wallets.register() |
ORGANIZATION_NOT_FOUND | API key’s org not found | Check API key |
TOKEN_NOT_FOUND | Token not supported | Check supported tokens |
Simulation Errors (4xx)
| Code | Description | Recommended Action |
|---|---|---|
INSUFFICIENT_GAS | Not enough SOL for transaction fee | Prompt user to add SOL |
SIMULATION_FAILED | Transaction simulation failed | Check error details |
if (error.is(ErrorCode.INSUFFICIENT_GAS)) {
showError('Please add SOL to cover transaction fees');
}
Authentication Errors (401/403)
| Code | Description | Recommended Action |
|---|---|---|
INVALID_API_KEY | API key not recognized | Check API key configuration |
API_KEY_DISABLED | API key has been revoked | Contact support |
API_KEY_ADDRESS_NOT_ALLOWED | The key has an allowlist and the request came from outside it. error.details.address is the address RebelFi saw | Send from an allowed server, or add that address to the key’s allowed addresses in the dashboard. The key is not suspended |
API_KEY_EXPIRED | The key passed its expiry | Create a new key and deploy it |
ORGANIZATION_PENDING_APPROVAL | Organization is waiting for RebelFi approval | Wait for approval, then retry. Do not create a second organization |
ORGANIZATION_SUSPENDED | Organization was suspended | Contact support. Retrying will not succeed until the organization is reinstated |
FORBIDDEN | The key is valid but cannot perform this action | Check the key’s permissions |
VALIDATION_FAILED | Request body failed validation | Read error.details for the field messages and fix the request |
if (error.is(ErrorCode.ORGANIZATION_PENDING_APPROVAL)) {
showError('This organization is waiting for approval');
}
if (error.is(ErrorCode.VALIDATION_FAILED)) {
// details is { [field]: message }
console.error(error.details);
}
if (error.is(ErrorCode.API_KEY_ADDRESS_NOT_ALLOWED)) {
// Add this address to the key's allowed addresses, or call from an allowed server
console.error(`RebelFi saw this request from ${error.details?.address}`);
}
if (error.is(ErrorCode.API_KEY_EXPIRED)) {
console.error('The RebelFi API key has expired. Create a new one in the dashboard.');
}
Rate Limiting (429)
| Code | Description | Recommended Action |
|---|---|---|
RATE_LIMIT_EXCEEDED | Too many requests | Implement backoff |
if (error.is(ErrorCode.RATE_LIMIT_EXCEEDED)) {
// Exponential backoff
await delay(retryCount * 1000);
return await retry();
}
Network Errors
| Code | Description | Recommended Action |
|---|---|---|
TIMEOUT | Request timed out | Retry with backoff. For submitSigned(), retry with the same signed transaction |
NETWORK_ERROR | Network connectivity issue | Check connection, retry |
INTERNAL_ERROR | Server error (500) or temporarily unavailable (503). From submitSigned(), 503 means the transaction could not be checked against the plan and nothing was broadcast | Retry; for submitSigned(), with the same signed transaction |
UNKNOWN_ERROR | Unexpected error | Log and report |
Error Details by Code
Many errors include adetails object with structured context. Here are the fields returned for each error code:
| Error Code | Details Fields | Example |
|---|---|---|
INSUFFICIENT_BALANCE | requested: string, available: string | { "requested": "1000000", "available": "500000" } |
OPERATION_IN_PROGRESS | operationId: number, walletId: number, status: OperationStatus (the blocking operation’s), expiresAt?: string (its signing deadline) | { "operationId": 123, "walletId": 45, "status": "AWAITING_SIGNATURE", "expiresAt": "2024-01-15T10:35:00.000Z" } |
OPERATION_EXPIRED | operationId: number, expiresAt?: string | { "operationId": 123, "expiresAt": "2024-01-15T10:35:00.000Z" } |
TRANSACTION_MISMATCH | operationId: number | { "operationId": 123 } |
OPERATION_ALREADY_SUBMITTED (409) | operationId: number, transactionId: number | { "operationId": 123, "transactionId": 456 } |
OPERATION_ALREADY_SUBMITTED (400) | operationId: number, resubmitSameTransaction: boolean | { "operationId": 123, "resubmitSameTransaction": true } |
INSUFFICIENT_GAS | walletAddress: string, blockchain: string | { "walletAddress": "So11...abc", "blockchain": "solana" } |
SIMULATION_FAILED | logs?: string[], unitsConsumed?: number | { "logs": ["Program log: Error"], "unitsConsumed": 50000 } |
TOKEN_MISMATCH | expected: string, actual: string | { "expected": "USDC", "actual": "USDT" } |
STRATEGY_NOT_ACTIVE | strategyId: number | { "strategyId": 1 } |
ALLOCATION_NOT_FOUND | strategyId: number, walletAddress: string | { "strategyId": 1, "walletAddress": "So11...abc" } |
API_KEY_ADDRESS_NOT_ALLOWED | address: string | { "address": "192.0.2.10" } |
WALLET_NOT_VERIFIED | orgWalletId: number (the wallet’s walletId) | { "orgWalletId": 42 } |
CLIENT_ACCOUNT_REQUIRED | orgWalletId: number | { "orgWalletId": 42 } |
CLIENT_ACCOUNT_NOT_ACTIVE | orgWalletId: number, accountId: number, status: string | { "orgWalletId": 42, "accountId": 17, "status": "PENDING_ACTIVATION" } |
WALLET_LINKED_TO_ANOTHER_ACCOUNT | walletId: number, accountId: number (requested), linkedAccountId: number | { "walletId": 42, "accountId": 18, "linkedAccountId": 17 } |
ACCOUNT_REFERENCE_CONFLICT | reference: string, accountId: number (the existing account) | { "reference": "CLIENT-0042", "accountId": 17 } |
Transaction Failure Codes
When a transaction fails, check thefailureCode for details:
const operation = await client.operations.get(operationId);
if (operation.status === 'FAILED') {
const tx = operation.transactions[0];
switch (tx.failureCode) {
case 'REVERTED':
console.error('Contract reverted:', tx.revertReason);
break;
case 'OUT_OF_GAS':
console.error('Transaction ran out of gas');
break;
case 'TIMEOUT':
console.error('Transaction not confirmed in time');
break;
case 'INSUFFICIENT_FUNDS':
console.error('Not enough SOL for gas');
break;
}
}
| Code | Description |
|---|---|
REVERTED | Smart contract execution reverted |
OUT_OF_GAS | Transaction ran out of gas |
TIMEOUT | Not included in block within timeout |
NONCE_TOO_LOW | Nonce already used (duplicate tx) |
INSUFFICIENT_FUNDS | Not enough native token for gas |
REPLACED | Transaction replaced by another |
DROPPED | Dropped from mempool |
UNKNOWN | Unknown failure reason |
Error Handling Patterns
Comprehensive Handler
import { RebelfiError, ErrorCode } from '@rebelfi/sdk';
async function handleSupply(params: SupplyParams) {
try {
const operation = await client.operations.supply(params);
return { success: true, operation };
} catch (error) {
if (!(error instanceof RebelfiError)) {
// Unexpected error
console.error('Unexpected error:', error);
return { success: false, error: 'An unexpected error occurred' };
}
// User-fixable errors
if (error.is(ErrorCode.INSUFFICIENT_BALANCE)) {
return {
success: false,
error: 'Insufficient balance',
userAction: 'add_funds'
};
}
if (error.is(ErrorCode.INSUFFICIENT_GAS)) {
return {
success: false,
error: 'Need SOL for transaction fee',
userAction: 'add_sol'
};
}
// Retryable errors
if (error.is(ErrorCode.RATE_LIMIT_EXCEEDED) ||
error.is(ErrorCode.TIMEOUT) ||
error.is(ErrorCode.NETWORK_ERROR)) {
return {
success: false,
error: 'Temporary error',
retryable: true
};
}
// Strategy issues
if (error.is(ErrorCode.STRATEGY_NOT_ACTIVE) ||
error.is(ErrorCode.STRATEGY_NOT_FOUND)) {
return {
success: false,
error: 'Strategy unavailable',
userAction: 'select_different_strategy'
};
}
// Auth issues
if (error.is(ErrorCode.INVALID_API_KEY) ||
error.is(ErrorCode.API_KEY_DISABLED) ||
error.is(ErrorCode.API_KEY_ADDRESS_NOT_ALLOWED) ||
error.is(ErrorCode.API_KEY_EXPIRED)) {
console.error('API key issue:', error.message);
return {
success: false,
error: 'Service configuration error'
};
}
// Unknown API error
return {
success: false,
error: error.message
};
}
}
Retry with Backoff
async function withRetry<T>(
fn: () => Promise<T>,
options: { maxAttempts?: number; baseDelay?: number } = {}
): Promise<T> {
const { maxAttempts = 3, baseDelay = 1000 } = options;
for (let attempt = 1; attempt <= maxAttempts; attempt++) {
try {
return await fn();
} catch (error) {
if (!(error instanceof RebelfiError)) throw error;
const isRetryable =
error.is(ErrorCode.TIMEOUT) ||
error.is(ErrorCode.NETWORK_ERROR) ||
error.is(ErrorCode.RATE_LIMIT_EXCEEDED);
if (!isRetryable || attempt === maxAttempts) {
throw error;
}
const delay = baseDelay * Math.pow(2, attempt - 1);
await new Promise(r => setTimeout(r, delay));
}
}
throw new Error('Max attempts reached');
}
// Usage
const operation = await withRetry(() =>
client.operations.supply(params)
);
Signing Deadline Handling
An operation must be signed and submitted before itsexpiresAt, five minutes after planning (on EVM, the supply after
an approve gets a fresh five minutes once the approve is submitted). Planning never returns OPERATION_EXPIRED;
getUnsignedTransactions() and submitSigned() do, once the deadline has passed. Plan again then: the expired plan
holds no transaction, so the new plan expires it in place.
If a submitSigned() failed with resubmitSameTransaction: true, or you reported a hash with submitHash(), the
operation stays live after its deadline until RebelFi sees whether that transaction landed. Poll operations.get()
until it leaves AWAITING_SIGNATURE before planning again; a plan meanwhile fails with OPERATION_IN_PROGRESS. If it
becomes SUBMITTED or CONFIRMED, the transaction landed and there is nothing to plan again.
async function supplyAndSubmit(params: SupplyParams, sign: (unsigned: string) => Promise<string>) {
const maxPlans = 2;
for (let i = 0; i < maxPlans; i++) {
const operation = await client.operations.supply(params);
const [tx] = await client.operations.getUnsignedTransactions(operation.operationId);
const signedTransaction = await sign(tx.unsignedTransaction.serialized);
try {
return await client.transactions.submitSigned({ operationId: operation.operationId, signedTransaction });
} catch (error) {
if (error instanceof RebelfiError && error.is(ErrorCode.OPERATION_EXPIRED)) {
console.log('Signing took longer than the deadline; planning again');
continue;
}
throw error;
}
}
throw new Error('Signing kept missing the deadline');
}
An
EXPIRED (or CANCELLED) operation can still become CONFIRMED: if a transaction you signed for it reaches the
chain after the deadline, RebelFi records it and alerts your organization. If you broadcast it yourself, report it with
submitHash(), which is never refused for the deadline.Next Steps
TypeScript Reference
Complete type definitions
API Reference
REST API documentation