diff --git a/backend/framework/sdk/src/main/java/io/metersphere/sdk/controller/handler/RestControllerExceptionHandler.java b/backend/framework/sdk/src/main/java/io/metersphere/sdk/controller/handler/RestControllerExceptionHandler.java index f5a849e50b..e9173b97c1 100644 --- a/backend/framework/sdk/src/main/java/io/metersphere/sdk/controller/handler/RestControllerExceptionHandler.java +++ b/backend/framework/sdk/src/main/java/io/metersphere/sdk/controller/handler/RestControllerExceptionHandler.java @@ -17,13 +17,14 @@ public class RestControllerExceptionHandler { @ResponseStatus(HttpStatus.BAD_REQUEST) @ExceptionHandler(MethodArgumentNotValidException.class) - public Map handleValidationExceptions(MethodArgumentNotValidException ex) { + public ResultHolder handleValidationExceptions(MethodArgumentNotValidException ex) { Map errors = new HashMap<>(); ex.getBindingResult().getAllErrors().forEach((error) -> { String fieldName = ((FieldError) error).getField(); String errorMessage = error.getDefaultMessage(); errors.put(fieldName, errorMessage); }); - return errors; + // 错误码待定 + return ResultHolder.error(40000, "Validation failed", errors); } } diff --git a/backend/framework/sdk/src/main/java/io/metersphere/sdk/controller/handler/ResultHolder.java b/backend/framework/sdk/src/main/java/io/metersphere/sdk/controller/handler/ResultHolder.java index a282ba4ff2..a8163e1940 100644 --- a/backend/framework/sdk/src/main/java/io/metersphere/sdk/controller/handler/ResultHolder.java +++ b/backend/framework/sdk/src/main/java/io/metersphere/sdk/controller/handler/ResultHolder.java @@ -1,9 +1,18 @@ package io.metersphere.sdk.controller.handler; +import lombok.Data; import org.apache.commons.lang3.builder.ReflectionToStringBuilder; import org.apache.commons.lang3.builder.ToStringStyle; +@Data public class ResultHolder { + // 请求是否成功 + private int code = 0; + // 描述信息 + private String message; + // 返回数据 + private Object data = ""; + public ResultHolder() { this.code = 0; } @@ -24,37 +33,6 @@ public class ResultHolder { this.data = data; } - // 请求是否成功 - private int code = 0; - // 描述信息 - private String message; - // 返回数据 - private Object data = ""; - - public int getCode() { - return code; - } - - public void setCode(int code) { - this.code = code; - } - - public String getMessage() { - return message; - } - - public void setMessage(String message) { - this.message = message; - } - - public Object getData() { - return data; - } - - public void setData(Object data) { - this.data = data; - } - public static ResultHolder success(Object obj) { return new ResultHolder(obj); }