Error Handling

ArtistAPhoto provides specific error types for different failure scenarios.

import {
  ArtistAPhoto,
  LicenseError,
  ImageLoadError,
  InvalidCropError,
  InvalidDimensionsError
} from 'artistasdk';

async function editImage(file) {
  try {
    await ArtistAPhoto.setLicenseKey(process.env.LICENSE_KEY);
    const editor = await ArtistAPhoto.fromFile(file);
    editor.filter('vintage').brightness(10);
    return await editor.toBlob('image/jpeg', 0.9);

  } catch (error) {
    if (error instanceof LicenseError) {
      console.error('License problem:', error.code);
    } else if (error instanceof ImageLoadError) {
      console.error('Could not load image');
    } else {
      console.error('Unexpected error:', error);
    }
  }
}

License Error Codes

CodeDescription
INVALID_KEYLicense key not found or invalid format
LICENSE_EXPIREDLicense has expired
LICENSE_REVOKEDLicense was revoked
LICENSE_DISABLEDLicense was disabled
NO_LICENSENo license key set (when calling refresh)