diff options
| author | Paul Buetow <paul@buetow.org> | 2026-05-21 17:47:08 +0300 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2026-05-21 17:47:08 +0300 |
| commit | 5582ebd43791c41e443c53c72db9e67cdb527d22 (patch) | |
| tree | 832ac98c0fd89cc26b0f3be5b724485d884533de /player-android/lib/utils | |
| parent | 12c967f39c35c5ffaf5714e77aae1e9b0c018733 (diff) | |
Implement PodcastListScreen and SubscribeDialog with podcast feed management (ab)
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Diffstat (limited to 'player-android/lib/utils')
| -rw-r--r-- | player-android/lib/utils/error_mappers.dart | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/player-android/lib/utils/error_mappers.dart b/player-android/lib/utils/error_mappers.dart index c1ca5e9..6ab9731 100644 --- a/player-android/lib/utils/error_mappers.dart +++ b/player-android/lib/utils/error_mappers.dart @@ -129,3 +129,40 @@ String createShareErrorMessage(Object error) { } return 'Unexpected error. Please try again.'; } + +/// Maps any thrown object from [PlayerApiClient.listSets] (used by +/// [PodcastListScreen]) to a UI string. +/// +/// Identical delegation strategy to [setsErrorMessage]: DioExceptions are +/// mapped by [dioConnectionErrorMessage]; all other exceptions fall back to a +/// generic message. Having a separate function preserves the option to add +/// podcast-specific status-code overrides later without altering the sets +/// helper (Open-Closed Principle). +String podcastListErrorMessage(Object error) { + if (error is DioException) { + return dioConnectionErrorMessage(error); + } + return 'Unexpected error. Please try again.'; +} + +/// Maps any thrown object from [PlayerApiClient.subscribePodcast] to a UI string. +/// +/// Adds human-readable messages for the common failure modes: +/// - 400: the feed URL is malformed or the server could not parse the feed. +/// - 403: the user is not an admin (subscribe requires admin privileges). +/// - 409/500: generic server-side failure (duplicate subscription, etc.). +/// +/// Kept as a separate top-level function (Open-Closed, DRY) so it can evolve +/// independently of the share and sets mappers. +String podcastErrorMessage(Object error) { + if (error is DioException) { + if (error.response?.statusCode == 400) { + return 'Invalid feed URL or the feed could not be parsed. Check the URL and try again.'; + } + if (error.response?.statusCode == 403) { + return 'Only administrators can subscribe to podcast feeds.'; + } + return dioConnectionErrorMessage(error); + } + return 'Unexpected error. Please try again.'; +} |
