userFriendlyMessage function Architecture

String userFriendlyMessage(
  1. Object error, {
  2. String? logName,
})

Maps raw exceptions to user-friendly messages for display in the UI.

Always logs the original error via dev.log before returning.

Implementation

String userFriendlyMessage(Object error, {String? logName}) {
  dev.log('Error: $error', name: logName ?? 'userFriendlyMessage');

  return switch (error) {
    AuthException e => _mapAuthException(e),
    PostgrestException _ => 'Failed to load data. Please try again.',
    FunctionException e => _mapFunctionException(e),
    AiApiException e => _mapAiApiException(e),
    DioException e => _mapDioException(e),
    StateError _ => 'Session expired. Please sign in again.',
    _ => 'Something went wrong. Please try again.',
  };
}