fix: completed better error managment for all api clients
This commit is contained in:
parent
6359efa0c3
commit
59e1c2558c
3 changed files with 65 additions and 37 deletions
|
|
@ -2,6 +2,7 @@ import 'dart:async';
|
|||
import 'dart:convert';
|
||||
|
||||
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
|
||||
import 'package:logger/logger.dart';
|
||||
import 'package:rxdart/rxdart.dart';
|
||||
import 'package:seshat/config/constants.dart';
|
||||
import 'package:seshat/domain/models/owner.dart';
|
||||
|
|
@ -15,20 +16,28 @@ class WebsocketClient {
|
|||
sync: true,
|
||||
);
|
||||
late final StreamSubscription sub;
|
||||
Logger log = Logger(
|
||||
printer: PrettyPrinter(
|
||||
colors: true,
|
||||
lineLength: 100,
|
||||
methodCount: 0,
|
||||
dateTimeFormat: DateTimeFormat.dateAndTime,
|
||||
),
|
||||
);
|
||||
|
||||
Stream<Owner> get owners => _ownersController.stream;
|
||||
|
||||
Future<void> _initStore() async {
|
||||
_secureStorage ??= const FlutterSecureStorage(
|
||||
aOptions: AndroidOptions(encryptedSharedPreferences: true),
|
||||
);
|
||||
_secureStorage ??= const FlutterSecureStorage();
|
||||
}
|
||||
|
||||
Future<void> connect() async {
|
||||
final url = "wss://$apiBasePath/ws";
|
||||
log.i("Webocket: $url");
|
||||
await _initStore();
|
||||
if (_channel != null) return;
|
||||
|
||||
_channel = WebSocketChannel.connect(Uri.parse("wss://$apiBasePath/ws"));
|
||||
_channel = WebSocketChannel.connect(Uri.parse(url));
|
||||
|
||||
await _channel!.ready;
|
||||
var token = await _secureStorage!.read(key: "token");
|
||||
|
|
|
|||
Reference in a new issue