You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shenyu.apache.org by de...@apache.org on 2021/08/04 13:34:26 UTC

[incubator-shenyu] branch master updated: Uniform the method name and regular the log format (#1865)

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

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


The following commit(s) were added to refs/heads/master by this push:
     new 17ea79c  Uniform the method name and regular the log format (#1865)
17ea79c is described below

commit 17ea79c435f3c5c168fc732d483bfd3955ffd2bc
Author: GuoJiwei <te...@apache.org>
AuthorDate: Wed Aug 4 21:34:18 2021 +0800

    Uniform the method name and regular the log format (#1865)
---
 .../shenyu/admin/exception/ExceptionHandlers.java  | 24 +++++++++++-----------
 .../listener/websocket/WebsocketListener.java      |  4 ++--
 .../admin/exception/ExceptionHandlersTest.java     | 10 ++++-----
 3 files changed, 19 insertions(+), 19 deletions(-)

diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/exception/ExceptionHandlers.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/exception/ExceptionHandlers.java
index 64edc67..3467db0 100644
--- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/exception/ExceptionHandlers.java
+++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/exception/ExceptionHandlers.java
@@ -50,7 +50,7 @@ import java.util.stream.Collectors;
 public class ExceptionHandlers {
 
     @ExceptionHandler(Exception.class)
-    protected ShenyuAdminResult serverExceptionHandler(final Exception exception) {
+    protected ShenyuAdminResult handleExceptionHandler(final Exception exception) {
         log.error(exception.getMessage(), exception);
         String message;
         if (exception instanceof ShenyuException) {
@@ -63,26 +63,26 @@ public class ExceptionHandlers {
     }
 
     @ExceptionHandler(DuplicateKeyException.class)
-    protected ShenyuAdminResult serverExceptionHandler(final DuplicateKeyException exception) {
-        log.error(exception.getMessage(), exception);
+    protected ShenyuAdminResult handleDuplicateKeyException(final DuplicateKeyException exception) {
+        log.error("duplicate key exception ", exception);
         return ShenyuAdminResult.error(ShenyuResultMessage.UNIQUE_INDEX_CONFLICT_ERROR);
     }
 
     @ExceptionHandler(UnauthorizedException.class)
-    protected ShenyuAdminResult shiroExceptionHandler(final UnauthorizedException exception) {
-        log.error(exception.getMessage(), exception);
+    protected ShenyuAdminResult handleUnauthorizedException(final UnauthorizedException exception) {
+        log.error("unauthorized exception", exception);
         return ShenyuAdminResult.error(CommonErrorCode.TOKEN_NO_PERMISSION, ShenyuResultMessage.TOKEN_HAS_NO_PERMISSION);
     }
 
     @ExceptionHandler(NullPointerException.class)
-    protected ShenyuAdminResult nullPointExceptionHandler(final NullPointerException exception) {
-        log.error(exception.getMessage(), exception);
+    protected ShenyuAdminResult handleNullPointException(final NullPointerException exception) {
+        log.error("null pointer exception ", exception);
         return ShenyuAdminResult.error(CommonErrorCode.NOT_FOUND_EXCEPTION, ShenyuResultMessage.NOT_FOUND_EXCEPTION);
     }
 
     @ExceptionHandler(HttpRequestMethodNotSupportedException.class)
     protected ShenyuAdminResult handleHttpRequestMethodNotSupportedException(final HttpRequestMethodNotSupportedException e) {
-        log.warn("", e);
+        log.warn("http request method not supported", e);
         StringBuilder sb = new StringBuilder();
         sb.append(e.getMethod());
         sb.append(
@@ -93,7 +93,7 @@ public class ExceptionHandlers {
 
     @ExceptionHandler(MethodArgumentNotValidException.class)
     protected ShenyuAdminResult handleMethodArgumentNotValidException(final MethodArgumentNotValidException e) {
-        log.warn("", e);
+        log.warn("method argument not valid", e);
         BindingResult bindingResult = e.getBindingResult();
         String errorMsg = bindingResult.getFieldErrors().stream()
                 .map(f -> f.getField().concat(": ").concat(Optional.ofNullable(f.getDefaultMessage()).orElse("")))
@@ -103,19 +103,19 @@ public class ExceptionHandlers {
 
     @ExceptionHandler(MissingServletRequestParameterException.class)
     protected ShenyuAdminResult handleMissingServletRequestParameterException(final MissingServletRequestParameterException e) {
-        log.warn("", e);
+        log.warn("missing servlet request parameter", e);
         return ShenyuAdminResult.error(String.format("%s parameter is missing", e.getParameterName()));
     }
 
     @ExceptionHandler(MethodArgumentTypeMismatchException.class)
     protected ShenyuAdminResult handleMethodArgumentTypeMismatchException(final MethodArgumentTypeMismatchException e) {
-        log.warn("", e);
+        log.warn("method argument type mismatch", e);
         return ShenyuAdminResult.error(String.format("%s should be of type %s", e.getName(), e.getRequiredType().getName()));
     }
 
     @ExceptionHandler(ConstraintViolationException.class)
     protected ShenyuAdminResult handleConstraintViolationException(final ConstraintViolationException e) {
-        log.warn("", e);
+        log.warn("constraint violation exception", e);
         Set<ConstraintViolation<?>> violations = e.getConstraintViolations();
         return ShenyuAdminResult.error(violations.stream()
                 .map(v -> v.getPropertyPath().toString().concat(": ").concat(v.getMessage()))
diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/listener/websocket/WebsocketListener.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/listener/websocket/WebsocketListener.java
index 8f6e083..25f63f0 100644
--- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/listener/websocket/WebsocketListener.java
+++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/listener/websocket/WebsocketListener.java
@@ -48,7 +48,7 @@ public class WebsocketListener implements ServletRequestListener {
                 session.removeAttribute(CLIENT_IP_NAME);
             }
         } catch (Exception e) {
-            log.error("", e);
+            log.error("request destroyed error", e);
         }
     }
 
@@ -62,7 +62,7 @@ public class WebsocketListener implements ServletRequestListener {
                 session.setAttribute(CLIENT_IP_NAME, sre.getServletRequest().getRemoteAddr());
             }
         } catch (Exception e) {
-            log.error("", e);
+            log.error("request initialized error", e);
         }
     }
 }
diff --git a/shenyu-admin/src/test/java/org/apache/shenyu/admin/exception/ExceptionHandlersTest.java b/shenyu-admin/src/test/java/org/apache/shenyu/admin/exception/ExceptionHandlersTest.java
index 6418f0b..099a45f 100644
--- a/shenyu-admin/src/test/java/org/apache/shenyu/admin/exception/ExceptionHandlersTest.java
+++ b/shenyu-admin/src/test/java/org/apache/shenyu/admin/exception/ExceptionHandlersTest.java
@@ -58,7 +58,7 @@ public final class ExceptionHandlersTest {
     @Test
     public void testServerExceptionHandlerByException() {
         Exception exception = new Exception();
-        ShenyuAdminResult result = exceptionHandlersUnderTest.serverExceptionHandler(exception);
+        ShenyuAdminResult result = exceptionHandlersUnderTest.handleExceptionHandler(exception);
         assertEquals(result.getCode().intValue(), CommonErrorCode.ERROR);
         assertEquals(result.getMessage(), "The system is busy, please try again later");
     }
@@ -66,7 +66,7 @@ public final class ExceptionHandlersTest {
     @Test
     public void testServerExceptionHandlerByShenyuException() {
         Exception shenyuException = new ShenyuException("Test shenyuException message!");
-        ShenyuAdminResult result = exceptionHandlersUnderTest.serverExceptionHandler(shenyuException);
+        ShenyuAdminResult result = exceptionHandlersUnderTest.handleExceptionHandler(shenyuException);
         assertEquals(result.getCode().intValue(), CommonErrorCode.ERROR);
         assertEquals(result.getMessage(), shenyuException.getMessage());
     }
@@ -74,7 +74,7 @@ public final class ExceptionHandlersTest {
     @Test
     public void testServerExceptionHandlerByDuplicateKeyException() {
         DuplicateKeyException duplicateKeyException = new DuplicateKeyException("Test duplicateKeyException message!");
-        ShenyuAdminResult result = exceptionHandlersUnderTest.serverExceptionHandler(duplicateKeyException);
+        ShenyuAdminResult result = exceptionHandlersUnderTest.handleDuplicateKeyException(duplicateKeyException);
         assertEquals(result.getCode().intValue(), CommonErrorCode.ERROR);
         assertEquals(result.getMessage(), ShenyuResultMessage.UNIQUE_INDEX_CONFLICT_ERROR);
     }
@@ -82,7 +82,7 @@ public final class ExceptionHandlersTest {
     @Test
     public void testShiroExceptionHandler() {
         UnauthorizedException unauthorizedException = mock(UnauthorizedException.class);
-        ShenyuAdminResult result = exceptionHandlersUnderTest.shiroExceptionHandler(unauthorizedException);
+        ShenyuAdminResult result = exceptionHandlersUnderTest.handleUnauthorizedException(unauthorizedException);
         assertEquals(result.getCode().intValue(), CommonErrorCode.TOKEN_NO_PERMISSION);
         assertEquals(result.getMessage(), ShenyuResultMessage.TOKEN_HAS_NO_PERMISSION);
     }
@@ -90,7 +90,7 @@ public final class ExceptionHandlersTest {
     @Test
     public void testNullPointExceptionHandler() {
         NullPointerException nullPointerException = mock(NullPointerException.class);
-        ShenyuAdminResult result = exceptionHandlersUnderTest.nullPointExceptionHandler(nullPointerException);
+        ShenyuAdminResult result = exceptionHandlersUnderTest.handleNullPointException(nullPointerException);
         assertEquals(result.getCode().intValue(), CommonErrorCode.NOT_FOUND_EXCEPTION);
         assertEquals(result.getMessage(), ShenyuResultMessage.NOT_FOUND_EXCEPTION);
     }