Error Handling
Typed error classes, status codes, request IDs, and best practices for handling API errors.
Error Classes
The SDK provides typed error classes for every failure scenario. Every error instance includes a request ID for support correlation.
import {
LendIQ,
LendIQError,
AuthenticationError,
NotFoundError,
ValidationError,
RateLimitError,
} from "@lendworks/lendiq";
const client = new LendIQ({ apiKey: "liq_live_..." });
try {
await client.deals.get(99999);
} catch (err) {
if (err instanceof NotFoundError) {
console.log("Deal not found");
console.log(err.statusCode); // 404
console.log(err.requestId); // "req_abc123"
console.log(err.body); // { error: "Deal not found" }
} else if (err instanceof AuthenticationError) {
console.log("Invalid credentials:", err.message);
} else if (err instanceof ValidationError) {
console.log("Validation failed:", err.body);
} else if (err instanceof RateLimitError) {
console.log(`Rate limited. Retry after ${err.retryAfter} seconds`);
} else if (err instanceof LendIQError) {
console.log(err.message, err.statusCode);
}
}from lendiq import (
LendIQ,
LendIQError,
AuthenticationError,
NotFoundError,
ValidationError,
RateLimitError,
)
client = LendIQ(api_key="liq_live_...")
try:
client.deals.get(99999)
except NotFoundError as e:
print("Deal not found")
print(e.status_code) # 404
print(e.request_id) # "req_abc123"
except AuthenticationError as e:
print("Invalid credentials:", e.message)
except ValidationError as e:
print("Validation failed:", e.body)
except RateLimitError as e:
print(f"Rate limited. Retry after {e.retry_after} seconds")
except LendIQError as e:
print(e.message, e.status_code)Error Types
| Class | Status | When |
|---|---|---|
AuthenticationError | 401 | Invalid or expired API key |
ValidationError | 422 | Request body fails validation |
NotFoundError | 404 | Resource does not exist |
RateLimitError | 429 | Rate limit exceeded (check retryAfter) |
LendIQError | Any | Base class for all other API errors |
Request ID Tracking
Every API response includes a request ID. You can access the last request ID on the client instance for logging and support correlation.
const deals = await client.deals.list();
console.log(client.lastRequestId); // "req_xyz789"deals = client.deals.list()
print(client.last_request_id) # "req_xyz789"