¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.product; |
| | | |
| | | import cn.hutool.json.JSONUtil; |
| | | import com.product.common.lang.StringUtils; |
| | | import com.product.core.exception.BaseException; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.web.bind.annotation.ExceptionHandler; |
| | | import org.springframework.web.bind.annotation.ResponseBody; |
| | | import org.springframework.web.bind.annotation.RestControllerAdvice; |
| | | |
| | | import java.util.HashMap; |
| | | import java.util.Map; |
| | | |
| | | /** |
| | | * @author cheng |
| | | * @date 2024å¹´9æ18æ¥10:17:42 |
| | | * @description å
¨å±å¼å¸¸å¤ç |
| | | */ |
| | | @RestControllerAdvice |
| | | @Slf4j |
| | | public class ChatServiceExceptionAdvice { |
| | | @ResponseBody |
| | | @ExceptionHandler(Exception.class) |
| | | public String exceptionHandler(Exception e) { |
| | | Map<String, Object> resultMap = new HashMap<>(); |
| | | resultMap.put("status", "error"); |
| | | if (e instanceof BaseException) { |
| | | BaseException exception = (BaseException) e; |
| | | resultMap.put("code", exception.getCode()); |
| | | resultMap.put("msg", exception.getMessage()); |
| | | log.error("å
¨å±å¼å¸¸æ¦æª", exception); |
| | | } else { |
| | | String message = e.getMessage(); |
| | | if (StringUtils.inString(message)) { |
| | | message = "æ¥å£è¯·æ±éè¯¯ï¼æªç¥å¼å¸¸"; |
| | | } else { |
| | | message = "æ¥å£è¯·æ±é误ï¼" + message; |
| | | } |
| | | resultMap.put("code", "00000"); |
| | | resultMap.put("msg", message); |
| | | log.error("å
¨å±å¼å¸¸æ¦æªï¼æªç¥å¼å¸¸", e); |
| | | } |
| | | return JSONUtil.toJsonStr(resultMap); |
| | | } |
| | | |
| | | |
| | | } |
| | | |
| | | |