package com.linhelp.common.exception; import com.linhelp.common.api.ApiResponse; import org.springframework.validation.BindException; import org.springframework.web.bind.MethodArgumentNotValidException; import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.bind.annotation.RestControllerAdvice; @RestControllerAdvice public class GlobalExceptionHandler { @ExceptionHandler(BizException.class) public ApiResponse handleBizException(BizException exception) { return ApiResponse.fail(exception.getCode(), exception.getMessage()); } @ExceptionHandler({MethodArgumentNotValidException.class, BindException.class}) public ApiResponse handleValidationException(Exception exception) { return ApiResponse.fail(422, "请求参数不正确"); } @ExceptionHandler(Exception.class) public ApiResponse handleException(Exception exception) { return ApiResponse.fail(500, "系统繁忙,请稍后再试"); } }