外卖项目day03-删除菜品-需求分析和功能实现---2

This commit is contained in:
xx
2026-11-21 13:30:57 +08:00
parent 7b995714cc
commit 7ca30b2457
4 changed files with 38 additions and 0 deletions
@@ -2,6 +2,7 @@ package com.sky.handler;
import com.sky.constant.MessageConstant;
import com.sky.exception.BaseException;
import com.sky.exception.DeletionNotAllowedException;
import com.sky.result.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
@@ -36,4 +37,16 @@ public class GlobalExceptionHandler {
return Result.error(MessageConstant.UNKNOWN_ERROR);
}
/**
* 捕获不允许删除异常处理
* @param ex
* @return
*/
@ExceptionHandler
// public Result exceptionHandler1(DeletionNotAllowedException ex){
public Result exceptionHandler1(BaseException ex){//多态!!!用来处理所有的自定义业务异常!!!
log.error("异常信息:{}", ex.getMessage());
return Result.error(ex.getMessage());
}
}