Browse Source

[new]增加登录失效时清空登录状态

zk 1 year ago
parent
commit
bfb7ce044c
2 changed files with 14 additions and 0 deletions
  1. 9 0
      lib/utils/common_utils.dart
  2. 5 0
      lib/utils/http_handler.dart

+ 9 - 0
lib/utils/common_utils.dart

@@ -1,3 +1,12 @@
 bool getBoolValue(bool? value) {
   return value ?? false;
 }
+
+String stringToUnicode(String input) {
+  StringBuffer unicodeString = StringBuffer();
+  for (int i = 0; i < input.length; i++) {
+    unicodeString
+        .write('\\u${input.codeUnitAt(i).toRadixString(16).padLeft(4, '0')}');
+  }
+  return unicodeString.toString();
+}

+ 5 - 0
lib/utils/http_handler.dart

@@ -1,6 +1,8 @@
 import 'dart:async';
 
 import 'package:electronic_assistant/base/base_response.dart';
+import 'package:electronic_assistant/data/consts/error_code.dart';
+import 'package:electronic_assistant/data/repositories/account_repository.dart';
 
 class HttpHandler {
   static FutureOr<T> Function(BaseResponse<T> value) handle<T>(
@@ -13,6 +15,9 @@ class HttpHandler {
           throw Exception('data is null');
         }
       } else {
+        if (response.code == ErrorCode.errorCodeNoLogin) {
+          accountRepository.logout();
+        }
         throw ServerErrorException(response.code, response.message);
       }
     };