import '../../core/domain/errors.dart';

String formatUserError(Object? error, {String fallback = '操作失败'}) {
  if (error == null) return fallback;
  if (error is DomainError) return error.message;

  final raw = error.toString().trim();
  if (raw.isEmpty) return fallback;

  return raw
      .replaceFirst(RegExp(r'^(Exception|StateError|TimeoutException):\s*'), '')
      .trim();
}
