xushiting 3 年之前
父節點
當前提交
04dec4a6ac
共有 5 個文件被更改,包括 978 次插入455 次删除
  1. 963 452
      dist/js/index.js
  2. 1 1
      dist/js/index.js.map
  3. 2 1
      src/EventsManager.js
  4. 1 1
      src/Socket.js
  5. 11 0
      src/util.js

文件差異過大導致無法顯示
+ 963 - 452
dist/js/index.js


文件差異過大導致無法顯示
+ 1 - 1
dist/js/index.js.map


+ 2 - 1
src/EventsManager.js

@@ -1,5 +1,6 @@
 import {logger} from "./Logger.js"
 import Actions from "./enum/Actions.js"
+import util from "./util.js"
 
 export default class EventsManager extends EventEmitter {
     constructor() {
@@ -52,7 +53,7 @@ export default class EventsManager extends EventEmitter {
                         logger.debug(s + " response code: " + _);
                         return
                     }
-                    const v = getErrorByCode(_)
+                    const v = util.getErrorByCode(_)
                       , y = new v(m);
                     this.off(r),
                     f(y),

+ 1 - 1
src/Socket.js

@@ -201,7 +201,7 @@ export default class Socket extends EventEmitter {
                             if (authenticationErrorCodes.indexOf(o) > -1)
                                 return this.emit("socketClosed", new AuthenticationError("\u9274\u6743\u9519\u8BEF:" + a));
                             {
-                                const s = getErrorByCode(o);
+                                const s = util.getErrorByCode(o);
                                 this.emit("socketClosed", new s(a))
                             }
                         }

+ 11 - 0
src/util.js

@@ -1,4 +1,8 @@
 
+import Codes from "./enum/Codes.js"
+import CodeErrorMap from "./error/CodeErrorMap.js"
+import InternalError from "./error/InternalError.js"
+
 var util = {
     uuid() {
         return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, i=>{
@@ -85,6 +89,13 @@ var util = {
     },
     getRandomItem(i){
         i.length === 0 ? null : i[Math.floor(Math.random() * i.length)]
+    },
+    getErrorByCode(i) {
+        if (i === Codes.Success)
+            return InternalError;
+        const e = CodeErrorMap[i];
+        return e || console.warn("unkown code", i),
+        e || InternalError
     }
 }
 export default util