Skip to main content

Overview

Proper error handling is critical for building robust applications with ZKScore. This guide covers common errors, handling strategies, and recovery patterns.

Common Errors

API Errors

try {
  const score = await zkScore.getScore(identity);
} catch (error) {
  if (error.code === 'IDENTITY_NOT_FOUND') {
    console.error('Identity does not exist');
  } else if (error.code === 'RATE_LIMIT_EXCEEDED') {
    console.error('Rate limit exceeded, please retry later');
  } else if (error.code === 'INVALID_API_KEY') {
    console.error('Invalid API key');
  } else {
    console.error('Unexpected error:', error.message);
  }
}

Error Types

CodeDescriptionAction
IDENTITY_NOT_FOUNDIdentity doesn’t existCheck ZKS ID
RATE_LIMIT_EXCEEDEDToo many requestsImplement backoff
INVALID_API_KEYAPI key invalidCheck credentials
NETWORK_ERRORNetwork failureRetry request

Best Practices

  1. Specific Handling: Handle each error type specifically
  2. User Feedback: Provide clear error messages
  3. Retry Logic: Implement exponential backoff
  4. Logging: Log errors for monitoring
  5. Graceful Degradation: Continue with limited functionality