at main 1.2 kB view raw
1/// Utility class for transforming technical error messages into 2/// user-friendly ones 3class ErrorMessages { 4 /// Transform technical error messages into user-friendly ones 5 static String getUserFriendly(String error) { 6 final lowerError = error.toLowerCase(); 7 8 if (lowerError.contains('socketexception') || 9 lowerError.contains('network') || 10 lowerError.contains('connection refused')) { 11 return 'Please check your internet connection'; 12 } else if (lowerError.contains('timeoutexception') || 13 lowerError.contains('timeout')) { 14 return 'Request timed out. Please try again'; 15 } else if (lowerError.contains('401') || 16 lowerError.contains('unauthorized')) { 17 return 'Authentication failed. Please sign in again'; 18 } else if (lowerError.contains('404') || lowerError.contains('not found')) { 19 return 'Content not found'; 20 } else if (lowerError.contains('500') || 21 lowerError.contains('internal server')) { 22 return 'Server error. Please try again later'; 23 } 24 25 // Fallback to generic message for unknown errors 26 return 'Something went wrong. Please try again'; 27 } 28}