2025-11-16 22:42:04 +01:00
|
|
|
import '../i18n/strings.g.dart';
|
|
|
|
|
import 'app_logger.dart';
|
2026-04-08 00:43:08 +02:00
|
|
|
import 'plex_http_exception.dart';
|
2025-11-16 22:42:04 +01:00
|
|
|
|
|
|
|
|
/// Shared helpers for translating network errors into user-friendly messages.
|
2026-04-08 00:43:08 +02:00
|
|
|
String mapHttpErrorToMessage(PlexHttpException error, {required String context}) {
|
2025-11-16 22:42:04 +01:00
|
|
|
switch (error.type) {
|
2026-04-08 00:43:08 +02:00
|
|
|
case PlexHttpErrorType.connectionTimeout:
|
|
|
|
|
case PlexHttpErrorType.receiveTimeout:
|
2025-11-16 22:42:04 +01:00
|
|
|
return t.errors.connectionTimeout(context: context);
|
2026-04-08 00:43:08 +02:00
|
|
|
case PlexHttpErrorType.connectionError:
|
2025-11-16 22:42:04 +01:00
|
|
|
return t.errors.connectionFailed;
|
|
|
|
|
default:
|
|
|
|
|
appLogger.e('Error loading $context', error: error);
|
2025-12-15 02:29:03 +01:00
|
|
|
return t.errors.failedToLoad(context: context, error: error.message ?? t.common.unknown);
|
2025-11-16 22:42:04 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Generic fallback for unexpected errors.
|
|
|
|
|
String mapUnexpectedErrorToMessage(dynamic error, {required String context}) {
|
|
|
|
|
appLogger.e('Unexpected error in $context', error: error);
|
2025-11-16 23:57:32 +01:00
|
|
|
return t.errors.failedToLoad(context: context, error: error.toString());
|
2025-11-16 22:42:04 +01:00
|
|
|
}
|