| New file |
| | |
| | | package com.mes.common.exception; |
| | | |
| | | import com.mes.utils.Result; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.web.bind.annotation.ControllerAdvice; |
| | | import org.springframework.web.bind.annotation.ExceptionHandler; |
| | | import org.springframework.web.bind.annotation.ResponseBody; |
| | | |
| | | /** |
| | | * @author zhoush |
| | | * @Date 2024/1/26 15:31 |
| | | */ |
| | | @ControllerAdvice |
| | | @Slf4j |
| | | public class GlobalExceptionHandler { |
| | | /** |
| | | * 如果是serviceExcaption,则调用该方法 |
| | | */ |
| | | @ExceptionHandler(ServiceException.class) |
| | | @ResponseBody |
| | | public Result handle(ServiceException se) { |
| | | return Result.error(se.getCode(), se.getMessage()); |
| | | } |
| | | |
| | | @ExceptionHandler(Exception.class) |
| | | @ResponseBody |
| | | public Result<Object> error(Exception e) { |
| | | e.printStackTrace(); |
| | | return Result.error(); |
| | | } |
| | | |
| | | } |