Files
LinHelp/backend/src/main/java/com/linhelp/common/exception/GlobalExceptionHandler.java

27 lines
1020 B
Java
Raw Normal View History

2026-07-07 15:10:03 +08:00
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<Void> handleBizException(BizException exception) {
return ApiResponse.fail(exception.getCode(), exception.getMessage());
}
@ExceptionHandler({MethodArgumentNotValidException.class, BindException.class})
public ApiResponse<Void> handleValidationException(Exception exception) {
return ApiResponse.fail(422, "请求参数不正确");
}
@ExceptionHandler(Exception.class)
public ApiResponse<Void> handleException(Exception exception) {
return ApiResponse.fail(500, "系统繁忙,请稍后再试");
}
}