mirror of
https://github.com/block/buzz.git
synced 2026-10-28 04:51:40 +00:00
fix(mobile): suppress failure callbacks for intentional auth cancellation
Signed-off-by: Tom Brow <tomb@block.xyz>
This commit is contained in:
@@ -16,6 +16,10 @@ import 'nostr_models.dart';
|
||||
/// Does NOT handle reconnection — that is [RelaySessionNotifier]'s job.
|
||||
enum SocketState { disconnected, connecting, authenticating, connected }
|
||||
|
||||
class _RelayDisconnectCancelled implements Exception {
|
||||
const _RelayDisconnectCancelled();
|
||||
}
|
||||
|
||||
class RelayAuthRejectedException implements Exception {
|
||||
final String message;
|
||||
|
||||
@@ -129,7 +133,7 @@ class RelaySocket {
|
||||
} catch (e) {
|
||||
_authTimeout?.cancel();
|
||||
await disconnect();
|
||||
_onDisconnected(e);
|
||||
if (e is! _RelayDisconnectCancelled) _onDisconnected(e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -140,7 +144,7 @@ class RelaySocket {
|
||||
|
||||
/// Gracefully close the connection.
|
||||
Future<void> disconnect() async {
|
||||
_failAuth(Exception('Relay disconnected during authentication'));
|
||||
_failAuth(const _RelayDisconnectCancelled());
|
||||
_resetConnection();
|
||||
final channel = _channel;
|
||||
_channel = null;
|
||||
|
||||
@@ -56,6 +56,7 @@ void main() {
|
||||
RelaySocket.debugPingInterval = RelaySocket.pingInterval;
|
||||
final server = await HttpServer.bind(InternetAddress.loopbackIPv4, 0);
|
||||
final authReceived = Completer<void>();
|
||||
final disconnectErrors = <Object?>[];
|
||||
WebSocket? peer;
|
||||
server.listen((request) async {
|
||||
final connection = await WebSocketTransformer.upgrade(request);
|
||||
@@ -73,7 +74,7 @@ void main() {
|
||||
nsec: nostr.Keys.generate().nsec,
|
||||
onMessage: (_) {},
|
||||
onConnected: () => fail('The peer never acknowledges authentication'),
|
||||
onDisconnected: (_) {},
|
||||
onDisconnected: disconnectErrors.add,
|
||||
);
|
||||
final connecting = socket.connect();
|
||||
try {
|
||||
@@ -82,6 +83,7 @@ void main() {
|
||||
await socket.disconnect();
|
||||
await connecting.timeout(const Duration(seconds: 1));
|
||||
expect(socket.state, SocketState.disconnected);
|
||||
expect(disconnectErrors, isEmpty);
|
||||
} finally {
|
||||
socket.dispose();
|
||||
await peer?.close();
|
||||
|
||||
Reference in New Issue
Block a user