Commit 2062cc96 by 丁伟峰

for test

1 parent 738f0ceb
package com.alibaba.cloud.integration.order.controller; package com.alibaba.cloud.integration.order.controller;
import org.springframework.http.HttpStatus;
import org.springframework.validation.BindException;
import com.alibaba.cloud.integration.common.Result; import com.alibaba.cloud.integration.common.Result;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.FieldError; import org.springframework.validation.FieldError;
...@@ -7,6 +8,7 @@ import org.springframework.web.bind.MethodArgumentNotValidException; ...@@ -7,6 +8,7 @@ import org.springframework.web.bind.MethodArgumentNotValidException;
import org.springframework.web.bind.annotation.ControllerAdvice; import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.ResponseStatus;
import java.util.Objects; import java.util.Objects;
...@@ -14,6 +16,16 @@ import java.util.Objects; ...@@ -14,6 +16,16 @@ import java.util.Objects;
@Slf4j @Slf4j
public class GlobalExceptionHandler { public class GlobalExceptionHandler {
// 处理 BindException 异常
@ExceptionHandler(BindException.class)
@ResponseStatus(HttpStatus.BAD_REQUEST) // 可选:设置响应状态码
@ResponseBody
public Result<?> handleBindException(BindException ex) {
// 处理异常并返回自定义的错误信息
log.error("======== xxxxxxxxxxx ====> {}", ex.toString());
return Result.failed("请求参数验证失败:" + ex.getMessage());
}
@ExceptionHandler(Exception.class) @ExceptionHandler(Exception.class)
@ResponseBody @ResponseBody
public Result<?> handleException(Exception e) { public Result<?> handleException(Exception e) {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!