wrap WebSocketChannelError errors into StreamWebSocketError.
Signed-off-by: Sahil Kumar <[email protected]>
This commit is contained in:
@@ -1,6 +1,10 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:equatable/equatable.dart';
|
||||
import 'package:stream_chat/src/core/error/chat_error_code.dart';
|
||||
import 'package:stream_chat/src/ws/websocket.dart';
|
||||
import 'package:stream_chat/stream_chat.dart';
|
||||
import 'package:web_socket_channel/web_socket_channel.dart';
|
||||
|
||||
///
|
||||
class StreamChatError with EquatableMixin implements Exception {
|
||||
@@ -32,6 +36,13 @@ class StreamWebSocketError extends StreamChatError {
|
||||
return StreamWebSocketError(message, data: data);
|
||||
}
|
||||
|
||||
///
|
||||
factory StreamWebSocketError.fromWebSocketChannelError(
|
||||
WebSocketChannelException error) {
|
||||
final message = error.message ?? '';
|
||||
return StreamWebSocketError(message);
|
||||
}
|
||||
|
||||
///
|
||||
int? get code => data?.code;
|
||||
|
||||
|
||||
@@ -325,6 +325,20 @@ class WebSocket with TimerHelper {
|
||||
void _onConnectionError(error, [stacktrace]) {
|
||||
_logger?.warning('Error occurred', error, stacktrace);
|
||||
|
||||
StreamWebSocketError wsError;
|
||||
if (error is WebSocketChannelException) {
|
||||
wsError = StreamWebSocketError.fromWebSocketChannelError(error);
|
||||
} else {
|
||||
wsError = StreamWebSocketError(error.toString());
|
||||
}
|
||||
|
||||
final completer = connectionCompleter;
|
||||
// complete with error if not yet completed
|
||||
if (completer != null && !completer.isCompleted) {
|
||||
// complete the connection with error
|
||||
completer.completeError(wsError);
|
||||
}
|
||||
|
||||
// resetting connect, reconnect request flag
|
||||
_resetRequestFlags();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user