⚠️ 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 ClassHTTP CodeDescription
InvalidAPIKeyError401API Key is missing, incorrectly formatted, or has been revoked.
UnauthorizedError403Request payload user ID does not match the API Key's developer account owner.
UserNotFoundError404Specified developer user ID doesn't exist.
APIKeyNotFoundError404The system failed to match the API Key verification query.
InsufficientCreditsError501Account credit balance is lower than the model credit cost.
VTONServerError5xxBackend 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);
  }
}