Merge branch 'krille/fix-broken-init' into 'main'

fix: Logout after failed init

See merge request famedly/famedlysdk!617
This commit is contained in:
Sorunome 2021-01-20 09:38:47 +00:00
commit b8053ff28d
1 changed files with 15 additions and 25 deletions

View File

@ -351,17 +351,12 @@ class Client extends MatrixApi {
response.userId == null) { response.userId == null) {
throw Exception('Registered but token, device ID or user ID is null.'); throw Exception('Registered but token, device ID or user ID is null.');
} }
try {
await init( await init(
newToken: response.accessToken, newToken: response.accessToken,
newUserID: response.userId, newUserID: response.userId,
newHomeserver: homeserver, newHomeserver: homeserver,
newDeviceName: initialDeviceDisplayName ?? '', newDeviceName: initialDeviceDisplayName ?? '',
newDeviceID: response.deviceId); newDeviceID: response.deviceId);
} catch (_) {
await logout().catchError((_) => null);
rethrow;
}
return response; return response;
} }
@ -401,7 +396,6 @@ class Client extends MatrixApi {
loginResp.userId == null) { loginResp.userId == null) {
throw Exception('Registered but token, device ID or user ID is null.'); throw Exception('Registered but token, device ID or user ID is null.');
} }
try {
await init( await init(
newToken: loginResp.accessToken, newToken: loginResp.accessToken,
newUserID: loginResp.userId, newUserID: loginResp.userId,
@ -410,10 +404,6 @@ class Client extends MatrixApi {
newDeviceID: loginResp.deviceId, newDeviceID: loginResp.deviceId,
); );
return loginResp; return loginResp;
} catch (_) {
await logout().catchError((_) => null);
rethrow;
}
} }
/// Sends a logout command to the homeserver and clears all local data, /// Sends a logout command to the homeserver and clears all local data,
@ -843,7 +833,7 @@ class Client extends MatrixApi {
return _sync(); return _sync();
} catch (e, s) { } catch (e, s) {
Logs().e('Initialization failed', e, s); Logs().e('Initialization failed', e, s);
clear(); await logout().catchError((_) => null);
onLoginStateChanged.addError(e, s); onLoginStateChanged.addError(e, s);
_initLock = false; _initLock = false;
rethrow; rethrow;