unify errors, refactor retry_queue

Signed-off-by: Sahil Kumar <[email protected]>
This commit is contained in:
Sahil Kumar
2021-06-02 17:56:38 +05:30
parent 927eb3c451
commit 12e6b9c500
18 changed files with 486 additions and 381 deletions
@@ -27,12 +27,12 @@ class AuthInterceptor extends Interceptor {
try {
token = await _tokenManager.loadToken();
} catch (_) {
final error = StreamChatError(ChatErrorCode.undefinedToken);
final error = StreamChatNetworkError(ChatErrorCode.undefinedToken);
final dioError = StreamChatDioError(
error: error,
requestOptions: options,
);
return handler.reject(dioError);
return handler.reject(dioError, true);
}
final params = {'user_id': token.userId};
final headers = {
@@ -17,5 +17,5 @@ class StreamChatDioError extends DioError {
);
@override
final StreamChatError error;
final StreamChatNetworkError error;
}
@@ -100,14 +100,15 @@ class StreamHttpClient {
void close({bool force = false}) => httpClient.close(force: force);
StreamChatNetworkError _parseError(DioError err) {
StreamChatNetworkError error;
// locally thrown dio error
if (err is StreamChatDioError) {
final code = err.error.code;
final message = err.error.message;
return StreamChatNetworkError.raw(code: code, message: message);
error = err.error;
} else {
// real network request dio error
error = StreamChatNetworkError.fromDioError(err);
}
// real network request dio error
return StreamChatNetworkError.fromDioError(err);
return error..stackTrace = err.stackTrace;
}
/// Handy method to make http GET request with error parsing.
@@ -29,7 +29,7 @@ class Event {
this.parentId,
this.extraData = const {},
this.isLocal = true,
}) : createdAt = createdAt ?? DateTime.now();
}) : createdAt = createdAt?.toUtc() ?? DateTime.now().toUtc();
/// Create a new instance from a json
factory Event.fromJson(Map<String, dynamic> json) =>
@@ -1,3 +1,4 @@
import 'dart:convert';
import 'dart:math' as math;
// This alphabet uses `A-Za-z0-9_-` symbols. The genetic algorithm helped
@@ -14,3 +15,11 @@ String randomId({int size = 21}) {
}
return id;
}
/// Creates a hash string from the passed [objects]
String generateHash(List<Object?> objects) {
final payload = json.encode(objects);
final payloadBytes = utf8.encode(payload);
final payloadB64 = base64.encode(payloadBytes);
return payloadB64;
}