exampleUsage function
void
exampleUsage()
Example of how to use the API service with error handling
Implementation
void exampleUsage() async {
final apiService = ExampleApiService.shared;
try {
// Fetch user profile
final userProfile = await apiService.fetchUserProfile('user123');
print('User profile: $userProfile');
// Create a new user
final newUser = await apiService.createUser({
'name': 'John Doe',
'email': 'john@example.com',
'password': 'securepassword',
});
print('New user created: $newUser');
} on GtdError catch (error) {
// Handle specific error codes
if (error.statusCode == 401) {
print('Authentication required. Please login again.');
} else if (error.errorCode == 'VALIDATION_ERROR') {
print('Please fix the following errors:');
print('Validation failed');
} else {
// Generic error handling
print('Error: ${error.message}');
}
} catch (e) {
print('Unexpected error: $e');
}
}