fix json decode, empty user info
Signed-off-by: fufesou <shuanglongchen@yeah.net>
This commit is contained in:
parent
e6bade2c5f
commit
c7a417b2fb
@ -51,17 +51,21 @@ class UserModel {
|
|||||||
final user = UserPayload.fromJson(data);
|
final user = UserPayload.fromJson(data);
|
||||||
_parseAndUpdateUser(user);
|
_parseAndUpdateUser(user);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
print('Failed to refreshCurrentUser: $e');
|
debugPrint('Failed to refreshCurrentUser: $e');
|
||||||
} finally {
|
} finally {
|
||||||
await updateOtherModels();
|
await updateOtherModels();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static Map<String, dynamic>? getLocalUserInfo() {
|
static Map<String, dynamic>? getLocalUserInfo() {
|
||||||
|
final userInfo = bind.mainGetLocalOption(key: 'user_info');
|
||||||
|
if (userInfo == '') {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
return json.decode(bind.mainGetLocalOption(key: 'user_info'));
|
return json.decode(userInfo);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
print('Failed to get local user info: $e');
|
debugPrint('Failed to get local user info "$userInfo": $e');
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -108,7 +112,7 @@ class UserModel {
|
|||||||
headers: authHeaders)
|
headers: authHeaders)
|
||||||
.timeout(Duration(seconds: 2));
|
.timeout(Duration(seconds: 2));
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
print("request /api/logout failed: err=$e");
|
debugPrint("request /api/logout failed: err=$e");
|
||||||
} finally {
|
} finally {
|
||||||
await reset();
|
await reset();
|
||||||
gFFI.dialogManager.dismissByTag(tag);
|
gFFI.dialogManager.dismissByTag(tag);
|
||||||
@ -126,7 +130,7 @@ class UserModel {
|
|||||||
try {
|
try {
|
||||||
body = jsonDecode(utf8.decode(resp.bodyBytes));
|
body = jsonDecode(utf8.decode(resp.bodyBytes));
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
print("login: jsonDecode resp body failed: ${e.toString()}");
|
debugPrint("login: jsonDecode resp body failed: ${e.toString()}");
|
||||||
rethrow;
|
rethrow;
|
||||||
}
|
}
|
||||||
if (resp.statusCode != 200) {
|
if (resp.statusCode != 200) {
|
||||||
@ -141,7 +145,7 @@ class UserModel {
|
|||||||
try {
|
try {
|
||||||
loginResponse = LoginResponse.fromJson(body);
|
loginResponse = LoginResponse.fromJson(body);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
print("login: jsonDecode LoginResponse failed: ${e.toString()}");
|
debugPrint("login: jsonDecode LoginResponse failed: ${e.toString()}");
|
||||||
rethrow;
|
rethrow;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -158,7 +162,7 @@ class UserModel {
|
|||||||
final resp = await http.get(Uri.parse('$url/api/login-options'));
|
final resp = await http.get(Uri.parse('$url/api/login-options'));
|
||||||
return jsonDecode(resp.body);
|
return jsonDecode(resp.body);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
print("queryLoginOptions: jsonDecode resp body failed: ${e.toString()}");
|
debugPrint("queryLoginOptions: jsonDecode resp body failed: ${e.toString()}");
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user