Unified error handling
Is your feature request related to a problem? Please describe.
Whenever I have to handle errors, I have to make separated checks for each platform
try {
await player.setUrl("https://s3.amazonaws.com/404-file.mp3");
} on PlayerException catch (e) {
if (Platform.isIos || Platform.macos) { ... }
...
// iOS/macOS: maps to NSError.code
// Android: maps to ExoPlayerException.type
// Web: maps to MediaError.code
print("Error code: ${e.code}");
// iOS/macOS: maps to NSError.localizedDescription
// Android: maps to ExoPlaybackException.getMessage()
// Web: a generic message
print("Error message: ${e.message}");
} on PlayerInterruptedException catch (e) {
// This call was interrupted since another audio source was loaded or the
// player was stopped or disposed before this audio source could complete
// loading.
print("Connection aborted: ${e.message}");
} catch (e) {
// Fallback for all errors
print(e);
}
Describe the solution you'd like A unified error handling system, without worring about the different platforms:
try {
await player.setUrl("https://s3.amazonaws.com/404-file.mp3");
} on PlayerException catch (e) {
switch (e.code) {
case PlayerExceptionCode.aborted:
break;
case PlayerExceptionCode.unknown:
break;
}
} catch (e) {
// Fallback for all errors
print(e);
}
Describe alternatives you've considered N/A
Additional context I'm running my app on Android, Web and Windows
I haven't done the cross-platform analysis of all different error messages to decide on the best categories, but in principle if someone does that, it would be a good idea. I guess it would start by listing all of the errors of each platform and then grouping them. In this case, the platform-specific exception should still be nested inside the general exception so an app can respond to platform-specific behaviours.