mobile bluesky app made with flutter lazurite.stormlightlabs.org/
mobile bluesky flutter
at main 49 lines 1.8 kB view raw
1import 'package:lazurite/src/features/dms/domain/outbox_error.dart'; 2import 'package:lazurite/src/infrastructure/auth/oauth_exceptions.dart'; 3import 'package:lazurite/src/infrastructure/network/network_failure.dart'; 4 5/// Returns a user-friendly error message for UI display. 6String errorMessage(Object? error, {String fallback = 'Something went wrong. Please try again.'}) { 7 if (error == null) return fallback; 8 9 if (error is NetworkFailure) { 10 return switch (error) { 11 ConnectionFailure() => 'Network error. Check your connection and try again.', 12 AuthFailure(:final requiresReauth) => 13 requiresReauth 14 ? 'Session expired. Please sign in again.' 15 : 'Authentication failed. Please try again.', 16 RateLimitFailure(:final retryAfter) => 17 retryAfter != null 18 ? 'Too many requests. Try again in ${retryAfter.inSeconds}s.' 19 : 'Too many requests. Try again later.', 20 ServerFailure() => 'Server error. Please try again later.', 21 ClientFailure(:final statusCode) => 22 statusCode == 404 23 ? 'Not found. The item may have been deleted.' 24 : 'Request failed. Please try again.', 25 DecodeFailure() => 'We received an unexpected response. Please try again.', 26 }; 27 } 28 29 if (error is OAuthException) { 30 return error.errorDescription ?? 'Authorization failed. Please try again.'; 31 } 32 33 if (error is ValidationError) { 34 return error.message ?? 'Invalid input. Please update and retry.'; 35 } 36 37 if (error is FormatException) { 38 return error.message.isNotEmpty ? error.message : fallback; 39 } 40 41 if (error is StateError) { 42 final message = error.message; 43 if (message.contains('authenticated')) { 44 return 'Please sign in to continue.'; 45 } 46 } 47 48 return fallback; 49}