Explorar o código

修改异常处理

tianboguang %!s(int64=3) %!d(string=hai) anos
pai
achega
d2c5782c3d

+ 10 - 2
platform-common/src/main/java/com/platform/exception/GlobalExceptionHandler.java

@@ -8,7 +8,7 @@ package com.platform.exception;
 
 
 import com.platform.entity.Result;
-import lombok.extern.log4j.Log4j2;
+import com.platform.utils.R;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.http.HttpStatus;
 import org.springframework.util.StringUtils;
@@ -30,9 +30,17 @@ public class GlobalExceptionHandler {
     @ResponseBody
     @ExceptionHandler(CommonBaseException.class)
     @ResponseStatus(HttpStatus.OK)
-    public Result runtimeExceptionHandler(HttpServletRequest request, CommonBaseException e) {
+    public Result CommonBaseExceptionHandler(HttpServletRequest request, CommonBaseException e) {
         log.error(request.getRequestURI() + ":" + e.getMsg());
         return Result.failure(StringUtils.isEmpty(e.getCode()) ? Result.CODE_FAILURE : e.getCode(), e.getMsg());
     }
 
+    @ResponseBody
+    @ExceptionHandler(RuntimeException.class)
+    @ResponseStatus(HttpStatus.OK)
+    public R runtimeExceptionHandler(HttpServletRequest request, RuntimeException e) {
+        log.error(request.getRequestURI() + ":" + e.getMessage());
+        return R.error(e.getMessage());
+    }
+
 }

+ 1 - 2
platform-shop/src/main/java/com/platform/service/impl/BrandServiceImpl.java

@@ -144,8 +144,7 @@ public class BrandServiceImpl implements BrandService {
     public int save(BrandEntity brand) {
         BrandEntity brandEntity = brandDao.findByName(brand.getName());
         if(brandEntity != null){
-            log.error("场景已经被绑定");
-            return 0;
+            throw new RuntimeException("直播间生成失败,已经存在相同名称直播间");
         }
         return brandDao.save(brand);
     }