You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shenyu.apache.org by xi...@apache.org on 2023/06/05 03:25:36 UTC

[shenyu] branch master updated: refactor checkUserPassword, not print known error log when startup (#4697)

This is an automated email from the ASF dual-hosted git repository.

xiaoyu pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shenyu.git


The following commit(s) were added to refs/heads/master by this push:
     new bc16c5fdc refactor checkUserPassword, not print known error log when startup (#4697)
bc16c5fdc is described below

commit bc16c5fdc36d9df337286f5fb16321464c1f11a0
Author: tomsun28 <to...@outlook.com>
AuthorDate: Mon Jun 5 11:25:28 2023 +0800

    refactor checkUserPassword, not print known error log when startup (#4697)
    
    Co-authored-by: dragon-zhang <zh...@apache.org>
---
 .../shenyu/admin/controller/DashboardUserController.java       |  7 ++++++-
 .../main/java/org/apache/shenyu/admin/utils/ResultUtil.java    | 10 ++++++++++
 2 files changed, 16 insertions(+), 1 deletion(-)

diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/controller/DashboardUserController.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/controller/DashboardUserController.java
index e9f7d9bdb..ce0f62ae0 100644
--- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/controller/DashboardUserController.java
+++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/controller/DashboardUserController.java
@@ -19,6 +19,7 @@ package org.apache.shenyu.admin.controller;
 
 import org.apache.commons.collections4.CollectionUtils;
 import org.apache.commons.lang3.StringUtils;
+import org.apache.shenyu.admin.exception.ValidFailException;
 import org.apache.shenyu.admin.mapper.DashboardUserMapper;
 import org.apache.shenyu.admin.model.custom.UserInfo;
 import org.apache.shenyu.admin.model.dto.DashboardUserDTO;
@@ -184,7 +185,11 @@ public class DashboardUserController {
      */
     @GetMapping("check/password")
     public AdminResult<Boolean> checkUserPassword() {
-        return ResultUtil.ok(dashboardUserService.checkUserPassword(SessionUtil.visitor().getUserId()));
+        try {
+            return ResultUtil.ok(dashboardUserService.checkUserPassword(SessionUtil.visitor().getUserId()));            
+        } catch (ValidFailException exception) {
+            return ResultUtil.error(exception.getMessage());
+        }
     }
     
     /**
diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/utils/ResultUtil.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/utils/ResultUtil.java
index 853e069b2..24bf9aab1 100644
--- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/utils/ResultUtil.java
+++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/utils/ResultUtil.java
@@ -60,4 +60,14 @@ public final class ResultUtil {
     public static <T> AdminResult<T> ok(final T data, final String message) {
         return new AdminResult<>(CommonErrorCode.SUCCESSFUL, message, data);
     }
+    
+    /**
+     * error.
+     * @param message response message
+     * @param <T>     response body type
+     * @return admin result
+     */
+    public static <T> AdminResult<T> error(final String message) {
+        return new AdminResult<>(CommonErrorCode.ERROR, message, null);
+    }
 }