Skip to content

Commit

Permalink
fix: Correctly throws final error when connection fails. (livekit#214)
Browse files Browse the repository at this point in the history
* fix: Correctly throws final error when connection fails.

* update.

* update.
  • Loading branch information
cloudwebrtc authored Dec 5, 2022
1 parent 06783ca commit 833fd65
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
13 changes: 6 additions & 7 deletions lib/src/core/signal_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ class SignalClient extends Disposable with EventsEmittable<SignalEvent> {
_updateConnectionState(ConnectionState.connected);
} catch (socketError) {
// Attempt Validation
var finalError = socketError;
try {
// Skip validation if reconnect mode
if (reconnect) rethrow;
Expand All @@ -106,17 +107,15 @@ class SignalClient extends Disposable with EventsEmittable<SignalEvent> {

final validateResponse = await http.get(validateUri);
if (validateResponse.statusCode != 200) {
throw ConnectException(validateResponse.body);
finalError = ConnectException(validateResponse.body);
}
throw ConnectException();
} catch (error) {
// Pass it up if it's already a `ConnectError`
if (error is ConnectException) rethrow;
// HTTP doesn't work either
throw ConnectException();
if (socketError.runtimeType != error.runtimeType) {
finalError = error;
}
} finally {
_updateConnectionState(ConnectionState.disconnected);
rethrow;
throw finalError;
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/src/exceptions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ abstract class LiveKitException implements Exception {
const LiveKitException._(this.message);

@override
String toString() => 'LiveKit Exception $runtimeType $message';
String toString() => 'LiveKit Exception: [$runtimeType] $message';
}

/// An exception occured while attempting to connect.
Expand Down

0 comments on commit 833fd65

Please sign in to comment.