resource icon indicating copy to clipboard operation
resource copied to clipboard

Unify Exceptions for io and web

Open lexaknyazev opened this issue 5 years ago • 0 comments

Resource.readAsBytes() and friends throw different exceptions depending on which platform is being used. Given that dart:io and dart:html are generally mutually exclusive, there's no way to safely type-test thrown exceptions using something like on FileSystemException catch (e).

This package could throw its own exceptions instead with fields filled from the corresponding platform-specific exception classes.

  • io_io.dart throws one of:
    class FileSystemException implements IOException {
      final String message;
      final String path;
      final OSError osError;
    }
    
    class HttpException implements IOException {
      final String message;
      final Uri uri;
    }
    
  • io_html.dart should check HTTP response code and throw from _httpGetBytes.

Common API could look like:

class ResourceException {
  final String message;
  final Uri uri;
  final Uri resolvedUri;
}

lexaknyazev avatar Nov 02 '19 14:11 lexaknyazev