Skip to content

Commit 5e7d3e6

Browse files
committed
chore: fix analyzer warning
1 parent fdfd43a commit 5e7d3e6

File tree

4 files changed

+18
-16
lines changed

4 files changed

+18
-16
lines changed

packages/stream_chat/lib/src/core/error/stream_chat_error.dart

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,11 @@ class StreamChatNetworkError extends StreamChatError {
7676
ChatErrorCode errorCode, {
7777
int? statusCode,
7878
this.data,
79+
StackTrace? stacktrace,
7980
this.isRequestCancelledError = false,
8081
}) : code = errorCode.code,
8182
statusCode = statusCode ?? data?.statusCode,
83+
stackTrace = stacktrace ?? StackTrace.current,
8284
super(errorCode.message);
8385

8486
///
@@ -87,8 +89,10 @@ class StreamChatNetworkError extends StreamChatError {
8789
required String message,
8890
this.statusCode,
8991
this.data,
92+
StackTrace? stacktrace,
9093
this.isRequestCancelledError = false,
91-
}) : super(message);
94+
}) : stackTrace = stacktrace ?? StackTrace.current,
95+
super(message);
9296

9397
///
9498
factory StreamChatNetworkError.fromDioException(DioException exception) {
@@ -108,8 +112,9 @@ class StreamChatNetworkError extends StreamChatError {
108112
'',
109113
statusCode: errorResponse?.statusCode ?? response?.statusCode,
110114
data: errorResponse,
115+
stacktrace: exception.stackTrace,
111116
isRequestCancelledError: exception.type == DioExceptionType.cancel,
112-
)..stackTrace = exception.stackTrace;
117+
);
113118
}
114119

115120
/// Error code
@@ -124,10 +129,8 @@ class StreamChatNetworkError extends StreamChatError {
124129
/// True, in case the error is due to a cancelled network request.
125130
final bool isRequestCancelledError;
126131

127-
StackTrace? _stackTrace;
128-
129-
///
130-
set stackTrace(StackTrace? stack) => _stackTrace = stack;
132+
/// The optional stack trace attached to the error.
133+
final StackTrace? stackTrace;
131134

132135
///
133136
ChatErrorCode? get errorCode => chatErrorCodeFromCode(code);
@@ -145,8 +148,8 @@ class StreamChatNetworkError extends StreamChatError {
145148
if (data != null) params += ', data: $data';
146149
var msg = 'StreamChatNetworkError($params)';
147150

148-
if (printStackTrace && _stackTrace != null) {
149-
msg += '\n$_stackTrace';
151+
if (printStackTrace && stackTrace != null) {
152+
msg += '\n$stackTrace';
150153
}
151154
return msg;
152155
}

packages/stream_chat/lib/src/core/http/interceptor/auth_interceptor.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ class AuthInterceptor extends QueuedInterceptor {
3030
final dioError = StreamChatDioError(
3131
error: error,
3232
requestOptions: options,
33+
stackTrace: StackTrace.current,
3334
);
3435
return handler.reject(dioError, true);
3536
}

packages/stream_chat/lib/src/core/http/stream_chat_dio_error.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,11 @@ class StreamChatDioError extends DioException {
99
required super.requestOptions,
1010
super.response,
1111
super.type,
12+
StackTrace? stackTrace,
13+
super.message,
1214
}) : super(
1315
error: error,
16+
stackTrace: stackTrace ?? StackTrace.current,
1417
);
1518

1619
@override

packages/stream_chat/lib/src/core/http/stream_http_client.dart

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -97,15 +97,10 @@ class StreamHttpClient {
9797
void close({bool force = false}) => httpClient.close(force: force);
9898

9999
StreamChatNetworkError _parseError(DioException exception) {
100-
StreamChatNetworkError error;
101100
// locally thrown dio error
102-
if (exception is StreamChatDioError) {
103-
error = exception.error;
104-
} else {
105-
// real network request dio error
106-
error = StreamChatNetworkError.fromDioException(exception);
107-
}
108-
return error..stackTrace = exception.stackTrace;
101+
if (exception is StreamChatDioError) return exception.error;
102+
// real network request dio error
103+
return StreamChatNetworkError.fromDioException(exception);
109104
}
110105

111106
/// Handy method to make http GET request with error parsing.

0 commit comments

Comments
 (0)