⚠️ Error Handling
Understand VTON SDK exceptions, error structures, and HTTP mappings.
Exception Mapping
The SDK exposes custom error classes corresponding to the different API response statuses. When an API call fails, the client throws the matching custom exception class so you can handle specific error codes cleanly in try-catch statements.
| SDK Error Class | HTTP Code | Description |
|---|---|---|
InvalidAPIKeyError | 401 | API Key is missing, incorrectly formatted, or has been revoked. |
UnauthorizedError | 403 | Request payload user ID does not match the API Key's developer account owner. |
UserNotFoundError | 404 | Specified developer user ID doesn't exist. |
APIKeyNotFoundError | 404 | The system failed to match the API Key verification query. |
InsufficientCreditsError | 501 | Account credit balance is lower than the model credit cost. |
VTONServerError | 5xx | Backend processing or rendering servers failed or timed out. |
Handling Errors
Use instance checks in catch blocks to handle specific edge conditions like credit depletion:
exception_handling.ts
import { VTONClient, InsufficientCreditsError, InvalidAPIKeyError } from 'snapit_sdk';
const client = new VTONClient();
try {
const result = await client.generateTryOn({
model_name: 'quality',
inputClothesImageUrls: ['https://assets.../garment.png']
});
} catch (error) {
if (error instanceof InsufficientCreditsError) {
console.error('Operation failed: Please buy more credit top-ups.');
} else if (error instanceof InvalidAPIKeyError) {
console.error('Unauthorized: Check your environment SMD_API_KEY value.');
} else {
console.error('SDK request failed:', error.message);
}
}