Browse Source

调整错误码

dygapp 4 years ago
parent
commit
5b86e70788
3 changed files with 11 additions and 11 deletions
  1. 6 6
      app/controller/admin.js
  2. 4 4
      app/controller/log.js
  3. 1 1
      app/controller/systemctl.js

+ 6 - 6
app/controller/admin.js

@@ -12,7 +12,7 @@ class AdminController extends Controller {
     console.log(data);
     let msg;
     if (data.length <= 0) {
-      msg = { errcode: -1, errmsg: '用户不存在' };
+      msg = { errcode: -1001, errmsg: '用户不存在' };
     } else {
       if (data[0].password === password) {
         const token = app.jwt.sign({ userName, name: data[0].name }, app.config.jwt.secret, {
@@ -20,7 +20,7 @@ class AdminController extends Controller {
         });
         msg = { errcode: 0, errmsg: '', token, userName, name: data[0].name };
       } else {
-        msg = { errcode: -1, errmsg: '密码错误' };
+        msg = { errcode: -1002, errmsg: '密码错误' };
       }
     }
     ctx.body = msg;
@@ -33,10 +33,10 @@ class AdminController extends Controller {
     let msg;
     try {
       if (data.length <= 0) {
-        msg = { errcode: -1, errmsg: '用户不存在' };
+        msg = { errcode: -1001, errmsg: '用户不存在' };
       } else {
         if (data[0].password === password) {
-          configJson.admin.map(p => {
+          configJson.admin.forEach(p => {
             if (p.userName === userName) {
               p.password = newpassword;
             }
@@ -45,12 +45,12 @@ class AdminController extends Controller {
           await this.service.fileshandler.write({ filePath: filePath.configJson, str: jsonstr });
           msg = { errcode: 0, errmsg: '' };
         } else {
-          msg = { errcode: -1, errmsg: '密码错误' };
+          msg = { errcode: -1002, errmsg: '密码错误' };
         }
       }
       ctx.body = msg;
     } catch (error) {
-      const body = { errcode: -1001, errmsg: '密码修改失败', error };
+      const body = { errcode: -1003, errmsg: '密码修改失败', error };
       throw new Error(JSON.stringify(body));
     }
   }

+ 4 - 4
app/controller/log.js

@@ -15,10 +15,10 @@ class LogController extends Controller {
       if (res.errcode === 0) {
         ctx.body = { errcode: 0, errmsg: '', data: res.data };
       } else {
-        this.ctx.body = { errcode: -0, errmsg: '获取日志失败' };
+        this.ctx.body = { errcode: -1006, errmsg: '获取日志失败' };
       }
     } catch (error) {
-      const body = { errcode: -1002, errmsg: '日志查询失败失败', error };
+      const body = { errcode: -1006, errmsg: '日志查询失败失败', error };
       throw new Error(JSON.stringify(body));
     }
   }
@@ -33,10 +33,10 @@ class LogController extends Controller {
       if (res) {
         this.ctx.body = res;
       } else {
-        this.ctx.body = { errcode: -0, errmsg: '下载日志失败' };
+        this.ctx.body = { errcode: -1007, errmsg: '下载日志失败' };
       }
     } catch (error) {
-      const body = { errcode: -1003, errmsg: '下载失败', error };
+      const body = { errcode: -1007, errmsg: '下载日志失败', error };
       throw new Error(JSON.stringify(body));
     }
   }

+ 1 - 1
app/controller/systemctl.js

@@ -109,7 +109,7 @@ class SystemctlController extends Controller {
       if (res.errcode === 0) {
         this.ctx.body = { errcode: 0, errmsg: 'ok' };
       } else {
-        this.ctx.body = { errcode: -0, errmsg: '设置系统时间失败' };
+        this.ctx.body = { errcode: -1028, errmsg: '设置系统时间失败' };
       }
     } catch (error) {
       const body = { errcode: -1028, errmsg: '设置系统时间失败', error };