xiaodai2017 2 years ago
parent
commit
4da9662742
1 changed files with 7 additions and 2 deletions
  1. 7 2
      src/hooks/useAsync.ts

+ 7 - 2
src/hooks/useAsync.ts

@@ -7,19 +7,24 @@ type Params = {
   code: number;
   message: string;
   handler: () => void;
+  errorHandler?: () => void;
 };
 
 export function useResponseHandle() {
   const { logout } = useNav();
 
-  function responseHandle({ code, message, handler }: Params) {
+  function responseHandle({ code, message, handler, errorHandler }: Params) {
     const c = Number(code);
     if (c === 0) {
       handler();
     } else if (c >= 100 && c <= 140) {
       logout();
     } else {
-      ElMessage.error(message);
+      if (errorHandler) {
+        errorHandler();
+      } else {
+        ElMessage.error(message);
+      }
     }
   }