Ver código fonte

异常处理

lgl 11 meses atrás
pai
commit
d98729889a

+ 8 - 2
src/main/java/com/liang/common/advice/ExceptionHandlerAdvice.java

@@ -30,9 +30,15 @@ import javax.validation.ConstraintViolationException;
30 30
 @RestControllerAdvice
31 31
 @Slf4j
32 32
 public class ExceptionHandlerAdvice {
33
-	@ExceptionHandler({IllegalArgumentException.class, CustomException.class})
33
+	@ExceptionHandler({CustomException.class})
34 34
 	@ResponseBody
35
-	public BaseResult parameterException(RuntimeException exception) {
35
+	public BaseResult customException(RuntimeException exception) {
36 36
 		return BaseResult.failure(ResultCode.FAIL,exception.getMessage());
37 37
 	}
38
+
39
+	@ExceptionHandler({IllegalArgumentException.class})
40
+	@ResponseBody
41
+	public BaseResult parameterException(RuntimeException exception) {
42
+		return BaseResult.failure(ResultCode.ILLEGALARGUMENT);
43
+	}
38 44
 }

+ 2 - 1
src/main/java/com/liang/common/enums/ResultCode.java

@@ -10,7 +10,8 @@ import lombok.AllArgsConstructor;
10 10
 public enum ResultCode {
11 11
 
12 12
     SUCCESS(0,"操作成功"),//成功
13
-    FAIL(-1,"操作失败");//失败
13
+    FAIL(-1,"操作失败"),//失败
14
+    ILLEGALARGUMENT(104,"参数异常");//失败
14 15
 
15 16
     private int code;
16 17