Client Error Handling

The Client SDK provides structured error handling to help you build resilient user interfaces.

Error Types

All errors extend ClientError.

Error ClassCode ExamplesDescription
AuthenticationErrorAUTH_INVALID_CREDENTIALS, AUTH_USER_EXISTSLogin/Register failures.
ValidationErrorVALIDATION_ERRORinvalid input data (email format, password length).
NetworkErrorNETWORK_ERROR, NETWORK_TIMEOUTConnection issues.

Handling Errors

The SDK provides helper methods to make error handling easier in your UI components.

import { ClientError } from '@aerostack/sdk';
 
try {
  await client.auth.login(email, password);
} catch (error) {
  if (error instanceof ClientError) {
    // 1. Check Error Type
    if (error.isAuthError()) {
      // Handle auth specific UI (e.g. shake password field)
    }
    
    if (error.isNetworkError()) {
      // Show offline toast
    }
 
    // 2. User-friendly Message
    // error.details.suggestion contains a message safe to show users
    alert(error.details.suggestion); 
    // e.g. "Double-check your email and password"
    
    // 3. Field specific errors
    if (error.details.field) {
      setError(error.details.field, error.message);
    }
  }
}

Use error.details.suggestion for displaying toast notifications or alerts to end-users. It contains human-readable, actionable advice.