diff --git a/pkgs/cupertino_http/lib/src/cupertino_web_socket.dart b/pkgs/cupertino_http/lib/src/cupertino_web_socket.dart index 5198b7bb17..080e3c12c8 100644 --- a/pkgs/cupertino_http/lib/src/cupertino_web_socket.dart +++ b/pkgs/cupertino_http/lib/src/cupertino_web_socket.dart @@ -203,7 +203,13 @@ class CupertinoWebSocket implements WebSocket { void _connectionClosed(int? closeCode, objc.NSData? reason) { if (!_events.isClosed) { - final closeReason = reason == null ? '' : utf8.decode(reason.toList()); + String closeReason; + + try { + closeReason = reason == null ? '' : utf8.decode(reason.toList()); + } on FormatException { + closeReason = 'unknown'; + } _events ..add(CloseReceived(closeCode, closeReason))