extractErrorMessage static method
Implementation
static String extractErrorMessage(String error) {
// Ищем код ошибки (например, 500)
final codeMatch = RegExp(r'^\d+').firstMatch(error);
final code = codeMatch != null ? codeMatch.group(0) : '';
// Ищем первую строку с русским текстом (например, "Хет-триков")
final lines = error.split('\n').map((e) => e.trim()).where((e) => e.isNotEmpty).toList();
String? message;
for (final line in lines) {
// Пропускаем строки, похожие на stacktrace и url
if (line.contains('://') || line.contains('->') || RegExp(r'^\d+').hasMatch(line)) continue;
// Берём первую строку с кириллицей или буквой
if (RegExp(r'[А-Яа-яA-Za-z]').hasMatch(line)) {
message = line;
break;
}
}
// Собираем результат
if (code != null && code.isNotEmpty && message != null) {
return '$code. $message';
} else if (code != null && code.isNotEmpty) {
return code;
} else if (message != null) {
return message;
}
return error;
}