mediaFailureCause function
The health cause for a media error, or null for network and 5xx noise.
Implementation
String? mediaFailureCause(String url, Object error) {
final trimmed = url.trim();
if (trimmed.isEmpty ||
trimmed.contains('{{') ||
Uri.tryParse(trimmed)?.hasScheme != true) {
return 'invalid_url';
}
if (error is FormatException) return 'decode';
// These media libraries expose no typed HTTP status here.
final message = '$error';
if (RegExp(r'(statusCode: |status |Response code: )4\d\d')
.hasMatch(message)) {
return 'http_4xx';
}
if (message.contains('Invalid image data')) return 'decode';
return null;
}