Improve connection error handling

This commit is contained in:
Igor Kulikov
2021-07-08 11:58:13 +03:00
parent 97cbb1d8bb
commit f0ce7d0b1d

View File

@@ -259,7 +259,11 @@ class TbContext {
userDetails = await tbClient.getUserService().getUser();
homeDashboard = await tbClient.getDashboardService().getHomeDashboardInfo();
} catch (e) {
tbClient.logout();
if (!_isConnectionError(e)) {
tbClient.logout();
} else {
rethrow;
}
}
}
} else {
@@ -272,9 +276,21 @@ class TbContext {
} catch (e, s) {
log.error('Error: $e', e, s);
if (_isConnectionError(e)) {
var res = await confirm(title: 'Connection error', message: 'Failed to connect to server', cancel: 'Cancel', ok: 'Retry');
if (res == true) {
onUserLoaded();
} else {
navigateTo('/login', replace: true, clearStack: true, transition: TransitionType.fadeIn, transitionDuration: Duration(milliseconds: 750));
}
}
}
}
bool _isConnectionError(e) {
return e is ThingsboardError && e.errorCode == ThingsBoardErrorCode.general && e.message == 'Unable to connect';
}
Listenable get isAuthenticatedListenable => _isAuthenticated;
bool get isAuthenticated => _isAuthenticated.value;