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
| Code | Description |
|---|---|
| INVALID_KEY | License key not found or invalid format |
| LICENSE_EXPIRED | License has expired |
| LICENSE_REVOKED | License was revoked |
| LICENSE_DISABLED | License was disabled |
| NO_LICENSE | No license key set (when calling refresh) |