Client Error Handling
The Client SDK provides structured error handling to help you build resilient user interfaces.
Error Types
All errors extend ClientError.
| Error Class | Code Examples | Description |
|---|---|---|
AuthenticationError | AUTH_INVALID_CREDENTIALS, AUTH_USER_EXISTS | Login/Register failures. |
ValidationError | VALIDATION_ERROR | invalid input data (email format, password length). |
NetworkError | NETWORK_ERROR, NETWORK_TIMEOUT | Connection 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.