package com.fdkankan.fusion.exception; import com.fdkankan.fusion.common.ResultCode; import com.fdkankan.fusion.exception.BusinessException; import com.fdkankan.fusion.common.ResultData; import lombok.extern.slf4j.Slf4j; import org.apache.tomcat.util.http.fileupload.impl.IOFileUploadException; import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.RestControllerAdvice; import org.springframework.web.multipart.MultipartException; /** * 全局异常处理器 */ @RestControllerAdvice @Slf4j public class GlobalExceptionHandler { /** * 处理未知异常 */ @ResponseBody @ExceptionHandler(value = Exception.class) public ResultData exceptionHandler(Exception e) throws Exception { log.error("服务错误:", e); return ResultData.error( 500, e.getMessage()); } /** * 处理业务异常 */ @ResponseBody @ExceptionHandler(value = BusinessException.class) public ResultData businessExceptionHandler(BusinessException e) { log.info("业务异常code:{},message:{}", e.getCode(), e.getMessage()); return ResultData.error(e.getCode(), e.getMessage()); } /** * 处理未知异常 */ @ResponseBody @ExceptionHandler(value = MultipartException.class) public ResultData iOFileUploadExceptionExceptionHandler(MultipartException e) { log.info("MultipartException:", e); return ResultData.error( ResultCode.SPACE_ERROR); } }