zhou-hao преди 7 години
родител
ревизия
d248b1e256

+ 16 - 4
hsweb-core/src/main/java/org/hswebframework/web/BusinessException.java

@@ -18,6 +18,8 @@
 
 package org.hswebframework.web;
 
+import lombok.Getter;
+
 /**
  * 业务异常
  *
@@ -27,12 +29,26 @@ package org.hswebframework.web;
 public class BusinessException extends RuntimeException {
     private static final long serialVersionUID = 5441923856899380112L;
 
+    @Getter
     private int status = 500;
 
+    @Getter
+    private String code;
+
     public BusinessException(String message) {
         this(message, 500);
     }
 
+    public BusinessException(String message, String code) {
+        this(message, code, 500);
+    }
+
+    public BusinessException(String message, String code, int status) {
+        super(message);
+        this.code = code;
+        this.status = status;
+    }
+
     public BusinessException(String message, int status) {
         super(message);
         this.status = status;
@@ -46,8 +62,4 @@ public class BusinessException extends RuntimeException {
         super(message, cause);
         this.status = status;
     }
-
-    public int getStatus() {
-        return status;
-    }
 }

+ 1 - 1
hsweb-starter/hsweb-spring-boot-starter/src/main/java/org/hswebframework/web/starter/RestControllerExceptionTranslator.java

@@ -75,7 +75,7 @@ public class RestControllerExceptionTranslator {
         if (exception.getCause() != null) {
             logger.error("{}:{}", exception.getMessage(), exception.getStatus(), exception.getCause());
         }
-        return ResponseMessage.error(exception.getStatus(), exception.getMessage());
+        return ResponseMessage.error(exception.getStatus(), exception.getMessage()).result(exception.getCode());
     }
 
     @ExceptionHandler(UnAuthorizedException.class)