Przeglądaj źródła

feat: 去除业务逻辑层错误日志报警

wangcheng 2 lat temu
rodzic
commit
76e1c068c2

+ 84 - 5
launch-admin/src/main/java/com/webflux/launchadmin/global/GlobalExceptionHandler.java

@@ -1,24 +1,103 @@
 package com.webflux.launchadmin.global;
 
-import com.alibaba.cola.dto.Response;
-import com.webflux.launchcommon.returnObj.RStatus;
+import com.alibaba.fastjson.JSON;
+import com.plumelog.core.util.LogExceptionStackTrace;
 import com.webflux.launchcommon.returnObj.RW;
 import lombok.extern.slf4j.Slf4j;
+import org.springframework.dao.DataAccessException;
 import org.springframework.http.HttpStatus;
+import org.springframework.util.MultiValueMap;
+import org.springframework.validation.BindException;
+import org.springframework.web.bind.MethodArgumentNotValidException;
 import org.springframework.web.bind.annotation.ExceptionHandler;
 import org.springframework.web.bind.annotation.ResponseBody;
 import org.springframework.web.bind.annotation.ResponseStatus;
 import org.springframework.web.bind.annotation.RestControllerAdvice;
+import org.springframework.web.multipart.MaxUploadSizeExceededException;
+import org.springframework.web.server.ServerWebExchange;
 import reactor.core.publisher.Mono;
 
+import javax.management.RuntimeErrorException;
+import javax.security.auth.login.AccountExpiredException;
+import java.io.IOException;
+import java.nio.file.AccessDeniedException;
+import java.sql.SQLException;
+import java.util.HashMap;
+import java.util.Map;
+
 @RestControllerAdvice
 @Slf4j
 public class GlobalExceptionHandler {
     @ResponseBody
     @ResponseStatus(HttpStatus.BAD_REQUEST)
+    @ExceptionHandler(BaseException.class)
+    public Mono<RW<Object>> handleException(BaseException e, ServerWebExchange exchange) {
+        log.warn("接口异常 uri={} e={}", exchange.getRequest().getPath().value(), e.getMessage());
+        return RW.fail("500", e.getMessage(), Mono.just(e.getMessage()));
+    }
+
+    /**
+     * 文件上传异常
+     */
+    @ExceptionHandler(MaxUploadSizeExceededException.class)
+    public Mono<RW<Object>> baseException(MaxUploadSizeExceededException e) {
+        return RW.fail("文件大小超出限制,请修改后重新上传。", Mono.just(e.getMessage()));
+    }
+
+    @ExceptionHandler(AccessDeniedException.class)
+    public Mono<RW<Object>> handleAuthorizationException(ServerWebExchange exchange, AccessDeniedException e) {
+        log.warn("接口异常 uri = {} e = {}", exchange.getRequest().getPath().value(), LogExceptionStackTrace.erroStackTrace(e));
+        return RW.fail(HttpStatus.FORBIDDEN.toString(), "没有权限,请联系管理员授权", Mono.just(e.getMessage()));
+    }
+
+    @ExceptionHandler(AccountExpiredException.class)
+    public Mono<RW<Object>> handleAccountExpiredException(ServerWebExchange exchange, AccountExpiredException e) {
+        log.warn("接口异常 uri = {} e = {}", exchange.getRequest().getPath().value(), LogExceptionStackTrace.erroStackTrace(e));
+        return RW.fail(e.getMessage(), Mono.just(e.getMessage()));
+    }
+
+    @ExceptionHandler(DataAccessException.class)
+    public Mono<RW<Object>> handleDataAccessException(ServerWebExchange exchange, AccountExpiredException e) {
+        log.error("接口异常 uri = {} e = {}", exchange.getRequest().getPath().value(), LogExceptionStackTrace.erroStackTrace(e));
+        return RW.fail(e.getMessage(), Mono.just(e.getMessage()));
+    }
+
     @ExceptionHandler(Exception.class)
-    public Mono<RW<Object>> handleException(Exception e) {
-        log.error(e.toString());
-        return RW.fail("500",e.getMessage(),Mono.just(e.getMessage()));
+    public Mono<RW<Object>> handleException(ServerWebExchange exchange, Exception e) {
+        if (e instanceof BaseException) {
+            try {
+                Map<String, Object> logger = new HashMap<>();
+                MultiValueMap<String, String> queryParams = exchange.getRequest().getQueryParams();
+                logger.put("param", queryParams);
+                String paramStr = JSON.toJSONString(logger);
+                log.info("裂变项目api请求记录:{}:{}", exchange.getRequest().getPath().value(), paramStr);
+            } catch (Exception e1) {
+                log.warn("裂变项目api请求记录异常:{}", LogExceptionStackTrace.erroStackTrace(e1));
+            }
+            log.warn("接口异常 uri= {} e= {}", exchange.getRequest().getPath().value(), LogExceptionStackTrace.erroStackTrace(e));
+        } else {
+            log.error("接口异常 uri = {} e = {}", exchange.getRequest().getPath().value(), LogExceptionStackTrace.erroStackTrace(e));
+        }
+        return RW.fail(e.getMessage(), Mono.just(e.getMessage()));
+    }
+
+    /**
+     * 自定义验证异常
+     */
+    @ExceptionHandler(BindException.class)
+    public Mono<RW<Object>> validatedBindException(ServerWebExchange exchange, BindException e) {
+        log.warn("接口异常 uri={} e={}", exchange.getRequest().getPath().value(), LogExceptionStackTrace.erroStackTrace(e));
+        String message = e.getAllErrors().get(0).getDefaultMessage();
+        return RW.fail(message, Mono.just(message));
+    }
+
+    /**
+     * 自定义验证异常
+     */
+    @ExceptionHandler(MethodArgumentNotValidException.class)
+    public Mono<RW<Object>> validExceptionHandler(ServerWebExchange exchange, MethodArgumentNotValidException e) {
+        log.warn("接口异常 uri={} e={}", exchange.getRequest().getPath().value(), LogExceptionStackTrace.erroStackTrace(e));
+        String message = e.getBindingResult().getFieldError().getDefaultMessage();
+        return RW.fail(message, Mono.just(message));
     }
 }

+ 38 - 39
launch-admin/src/main/java/com/webflux/launchadmin/mysql/controller/planNew/PlanNewCommonOutController.java

@@ -7,16 +7,17 @@ import cn.hutool.core.util.StrUtil;
 import cn.hutool.json.JSONArray;
 import cn.hutool.json.JSONObject;
 import cn.hutool.json.JSONUtil;
-import com.alibaba.fastjson.JSON;
 import com.plumelog.core.util.LogExceptionStackTrace;
 import com.webflux.launchadmin.global.BaseException;
-import com.webflux.launchadmin.mysql.controller.planNew.req.*;
+import com.webflux.launchadmin.mysql.controller.planNew.req.KefuRequest;
+import com.webflux.launchadmin.mysql.controller.planNew.req.OutDomainRequest;
+import com.webflux.launchadmin.mysql.controller.planNew.req.PlanNewCommonMaterialReq;
+import com.webflux.launchadmin.mysql.controller.planNew.req.PlanNewCommonShareReq;
 import com.webflux.launchadmin.mysql.controller.planNew.res.*;
 import com.webflux.launchadmin.mysql.controller.takeawayController.res.TakeawayH5Data;
 import com.webflux.launchadmin.mysql.entity.groupUsers.GroupUsers;
 import com.webflux.launchadmin.mysql.entity.listening.ListeningPlanNew;
 import com.webflux.launchadmin.mysql.entity.planNew.*;
-import com.webflux.launchadmin.mysql.entity.redis.RedisKey;
 import com.webflux.launchadmin.mysql.service.planNew.goGenerate.GoGenerateService;
 import com.webflux.launchadmin.mysql.service.planNew.ipAnalyze.IpAnalyzeServiceInterface;
 import com.webflux.launchadmin.mysql.service.planNew.structure.GoRequest;
@@ -24,14 +25,11 @@ import com.webflux.launchadmin.mysql.service.planNew.structure.Item;
 import com.webflux.launchadmin.mysql.service.takeaway.TakeawayServicesInterface;
 import com.webflux.launchcommon.returnObj.RStatus;
 import jakarta.annotation.Resource;
-import jakarta.json.Json;
 import lombok.extern.slf4j.Slf4j;
-import org.apache.commons.lang3.exception.ExceptionUtils;
 import org.springframework.data.domain.Sort;
 import org.springframework.data.r2dbc.core.R2dbcEntityTemplate;
 import org.springframework.data.redis.core.ReactiveRedisTemplate;
 import org.springframework.data.redis.core.RedisTemplate;
-import org.springframework.data.redis.core.StringRedisTemplate;
 import org.springframework.data.relational.core.query.Criteria;
 import org.springframework.data.relational.core.query.Query;
 import org.springframework.scheduling.annotation.Scheduled;
@@ -86,8 +84,8 @@ public class PlanNewCommonOutController {
     @GetMapping("getPlanNewCommonH5")
     public Mono<RStatus<byte[]>> getPlanNewCommonH5(@RequestParam("code") String code) {
         Mono<PlanNewCommon> planNewCommonMono = template.selectOne(Query.query(Criteria.where("code").is(code)), PlanNewCommon.class)
-                .switchIfEmpty(Mono.error(new BaseException("计划code异常" + ExceptionUtils.getStackTrace(new Exception()))))
-                .onErrorResume(throwable -> Mono.error(new Exception(LogExceptionStackTrace.erroStackTrace(throwable).toString())));
+                .switchIfEmpty(Mono.error(new BaseException("计划code异常")))
+                .onErrorResume(throwable -> Mono.error(new BaseException("计划code异常")));
         Mono<PlanNewCommonRes> resMono = planNewCommonMono.flatMap(f -> {
             // 群成员
             Mono<List<GroupUserRes>> groupUserResMono = Mono.just(new ArrayList<>());
@@ -95,16 +93,16 @@ public class PlanNewCommonOutController {
             Mono<List<Image>> imageMono = template.select(Query.query(Criteria.where("type").is(1)
                             .and("group_type_id").is(f.groupId())
                             .and("deleted_at").isNull()), Image.class)
-                    .onErrorResume(throwable -> Mono.error(new Exception(LogExceptionStackTrace.erroStackTrace(throwable).toString()))).collectList();
+                    .onErrorResume(throwable -> Mono.error(new BaseException("获取群封面异常"))).collectList();
             // 群名称
             Mono<List<Material>> textMono = template.select(Query.query(Criteria.where("type").is(4)
                             .and("deleted_at").isNull()
                             .and("group_type_id").is(f.groupId())), Material.class)
-                    .onErrorResume(throwable -> Mono.error(new Exception(LogExceptionStackTrace.erroStackTrace(throwable).toString()))).collectList();
+                    .onErrorResume(throwable -> Mono.error(new BaseException("获取群名称异常"))).collectList();
             if (3 == f.type()) {
                 // 交友裂变, 需要群成员
                 Mono<List<GroupUsers>> groupUsersMono = template.select(Query.query(Criteria.where("group_users_type").is(f.groupId())).limit(14), GroupUsers.class)
-                        .onErrorResume(throwable -> Mono.error(new Exception(LogExceptionStackTrace.erroStackTrace(throwable).toString()))).collectList();
+                        .onErrorResume(throwable -> Mono.error(new BaseException("获取群成员异常"))).collectList();
                 groupUserResMono = groupUsersMono.flatMap(groupUsers -> {
                     List<GroupUserRes> groupUserResList = groupUsers.stream().map(groupUsers1 -> {
                         GroupUserRes groupUserRes = new GroupUserRes();
@@ -176,7 +174,7 @@ public class PlanNewCommonOutController {
     public Mono<RStatus<byte[]>> kefuList(@RequestBody KefuRequest request) {
         Mono<PlanNewCommon> code = template.selectOne(Query.query(Criteria.where("code").is(request.getCode())), PlanNewCommon.class)
                 .switchIfEmpty(Mono.error(new BaseException("code查询返回结构为空")))
-                .onErrorResume(throwable -> Mono.error(new Exception(LogExceptionStackTrace.erroStackTrace(throwable).toString())));
+                .onErrorResume(throwable -> Mono.error(new BaseException("code查询返回结构为空")));
         Mono<DataListsKefu> dataListsKefuMono = code.flatMap(planNew -> {
             Mono<List<Image>> image = template.select(Query.query(Criteria.where("type").is(5)
                             .and("deleted_at").isNull()
@@ -184,13 +182,13 @@ public class PlanNewCommonOutController {
                     .collectList()
                     .switchIfEmpty(Mono.error(new BaseException(StrUtil.format("通过计划groupId:{}查询Image返回结构为空", planNew.groupId()))))
                     .onErrorResume(throwable ->
-                            Mono.error(new Exception(StrUtil.format("通过计划groupId:{}查询Image返回结果error:{}", planNew.groupId(), LogExceptionStackTrace.erroStackTrace(throwable).toString()))));
+                            Mono.error(new BaseException(StrUtil.format("通过计划groupId:{}查询Image返回结果error:{}", planNew.groupId(), throwable.getMessage()))));
             Mono<List<Material>> text = template.select(Query.query(Criteria.where("type").is(11)
                             .and("group_type_id").is(planNew.groupId())
                             .and("deleted_at").isNull()), Material.class)
                     .switchIfEmpty(Mono.error(new BaseException(StrUtil.format("通过计划groupId:{}查询Material返回结构为空", planNew.groupId()))))
                     .onErrorResume(throwable ->
-                            Mono.error(new Exception(StrUtil.format("通过计划groupId:{}查询Material返回结果error:{}", planNew.groupId(), LogExceptionStackTrace.erroStackTrace(throwable).toString()))))
+                            Mono.error(new BaseException(StrUtil.format("通过计划groupId:{}查询Material返回结果error:{}", planNew.groupId(), throwable.getMessage()))))
                     .collectList();
             Mono<List<H5ImageAndText>> arrayListMono = Mono.zip(Mono.just(planNew), image, text).flatMap(f -> {
                 // H5ImageAndText
@@ -199,7 +197,7 @@ public class PlanNewCommonOutController {
                 List<Image> t3 = f.getT2();
                 List<Material> t4 = f.getT3();
                 if (t3.size() < integer || t4.size() < integer) {
-                    throw new BaseException("图片或文字素材小于计划设置数");
+                    return Mono.error(new BaseException("图片或文字素材小于计划设置数"));
                 }
                 ArrayList<Long> listImg = new ArrayList<>();
                 ArrayList<Long> listTxt = new ArrayList<>();
@@ -273,7 +271,7 @@ public class PlanNewCommonOutController {
             // 交友裂变
             return this.getFriendPlan(request);
         }
-       // throw new BaseException("typePlan 类型错误");
+        // throw new BaseException("typePlan 类型错误");
     }
 
     /**
@@ -283,7 +281,7 @@ public class PlanNewCommonOutController {
         Mono<PlanNew> code1 = template
                 .selectOne(Query.query(Criteria.where("code").is(request.getCode())), PlanNew.class)
                 .switchIfEmpty(Mono.error(new BaseException("计划code异常 返回结果为空")))
-                .onErrorResume(throwable -> Mono.error(new Exception(LogExceptionStackTrace.erroStackTrace(throwable).toString())));
+                .onErrorResume(throwable -> Mono.error(new BaseException("计划code异常")));
         Mono<DomainSelectRes> domainSelectResMono1 = code1.flatMap(f -> {
             Mono<String> stringMono;
             if (f.transferPageBl() == 1 && Objects.nonNull(f.transferPageDomain())) {
@@ -293,7 +291,7 @@ public class PlanNewCommonOutController {
                                 .and("type").is(5)
                                 .and("deleted_at").isNull()), DomainSelect.class)
                         .switchIfEmpty(Mono.error(new BaseException("transferPageDomain 域名查詢為空 group_type_id:::" + f.transferPageDomain())))
-                        .onErrorResume(throwable -> Mono.error(new Exception(LogExceptionStackTrace.erroStackTrace(throwable).toString()))).collectList().flatMap(fff -> {
+                        .onErrorResume(throwable -> Mono.error(new BaseException("transferPageDomain 域名查詢為空 group_type_id:::" + f.transferPageDomain()))).collectList().flatMap(fff -> {
                             if (!fff.isEmpty()) {
                                 DomainSelect domainSelect = fff.get(RandomUtil.randomInt(0, fff.size()));
                                 String string = RandomUtil.randomString("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", 6);
@@ -301,7 +299,7 @@ public class PlanNewCommonOutController {
                                 return Mono.just(string + "." + domain1);
 
                             } else {
-                                throw new BaseException("transferPageDomain 中轉域名查詢為空 group_type_id:::" + f.transferPageDomain());
+                                return Mono.error(new BaseException("transferPageDomain 中轉域名查詢為空 group_type_id:::" + f.transferPageDomain()));
                             }
                         });
             } else {
@@ -315,14 +313,14 @@ public class PlanNewCommonOutController {
                                 .and("type").is(4)
                                 .and("deleted_at").isNull()), DomainSelect.class)
                         .switchIfEmpty(Mono.error(new BaseException("backgroupDomain 域名查询为空 group_type_id" + f.backgroupDomain())))
-                        .onErrorResume(throwable -> Mono.error(new Exception(LogExceptionStackTrace.erroStackTrace(throwable).toString()))).collectList().flatMap(fff -> {
+                        .onErrorResume(throwable -> Mono.error(new BaseException("backgroupDomain 域名查询为空 group_type_id" + f.backgroupDomain()))).collectList().flatMap(fff -> {
                             if (!fff.isEmpty()) {
                                 DomainSelect domainSelect = fff.get(RandomUtil.randomInt(0, fff.size()));
                                 String string = RandomUtil.randomString("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", 6);
                                 String domain1 = domainSelect.domain();
                                 return Mono.just(string + "." + domain1);
                             } else {
-                                throw new BaseException("backgroupDomain 背景域名查詢為空 group_type_id" + f.backgroupDomain());
+                                return Mono.error(new BaseException("backgroupDomain 背景域名查詢為空 group_type_id" + f.backgroupDomain()));
                             }
                         });
             } else {
@@ -334,7 +332,7 @@ public class PlanNewCommonOutController {
                             .and("type").is(request.getType())
                             .and("deleted_at").isNull()), DomainSelect.class)
                     .switchIfEmpty(Mono.error(new BaseException("查询domain 返回结果为空")))
-                    .onErrorResume(throwable -> Mono.error(new Exception(LogExceptionStackTrace.erroStackTrace(throwable).toString()))).collectList().flatMap(fm -> {
+                    .onErrorResume(throwable -> Mono.error(new BaseException("查询domain 返回结果为空"))).collectList().flatMap(fm -> {
                         //  DomainSelectRes domainSelectRes = new DomainSelectRes();
                         int i = RandomUtil.randomInt(0, fm.size());
                         String domain = fm.get(i).domain();
@@ -361,14 +359,14 @@ public class PlanNewCommonOutController {
     private Mono<RStatus<DomainSelectRes>> getListeningPlan(OutDomainRequest request) {
         Mono<ListeningPlanNew> code1 = template.selectOne(Query.query(Criteria.where("code").is(request.getCode())), ListeningPlanNew.class)
                 .switchIfEmpty(Mono.error(new BaseException("计划code异常 返回结果为空")))
-                .onErrorResume(throwable -> Mono.error(new Exception(LogExceptionStackTrace.erroStackTrace(throwable).toString())));
+                .onErrorResume(throwable -> Mono.error(new BaseException("计划code异常 返回结果为空")));
         Mono<DomainSelectRes> domainSelectResMono1 = code1.flatMap(f -> template.select(Query.query(Criteria
                         .where("group_type_id").is(f.groupId())
                         .and("status").is(1)
                         .and("type").is(request.getType())
                         .and("deleted_at").isNull()), DomainSelect.class)
                 .switchIfEmpty(Mono.error(new BaseException("查询domain 返回结果为空")))
-                .onErrorResume(throwable -> Mono.error(new Exception(LogExceptionStackTrace.erroStackTrace(throwable).toString()))).collectList()
+                .onErrorResume(throwable -> Mono.error(new BaseException("查询domain 返回结果为空"))).collectList()
                 .flatMap(fm -> {
                     DomainSelectRes domainSelectRes = new DomainSelectRes();
                     int i = RandomUtil.randomInt(0, fm.size());
@@ -396,7 +394,7 @@ public class PlanNewCommonOutController {
                             .and("deleted_at").isNull()
                             .and("type").is(request.getType())), DomainSelect.class)
                     .switchIfEmpty(Mono.error(new BaseException("查询domain 返回结果为空")))
-                    .onErrorResume(throwable -> Mono.error(new Exception(LogExceptionStackTrace.erroStackTrace(throwable).toString())))
+                    .onErrorResume(throwable -> Mono.error(new BaseException("查询domain 返回结果为空")))
                     .collectList().flatMap(fm -> {
                         int i = RandomUtil.randomInt(0, fm.size());
                         String domain = fm.get(i).domain();
@@ -424,7 +422,7 @@ public class PlanNewCommonOutController {
     public Mono<RStatus<PlanNewCommonMaterialRes>> getCommonMaterial(@RequestBody PlanNewCommonMaterialReq request) {
         Mono<PlanNewCommon> planNewCommonMono = template.selectOne(Query.query(Criteria.where("code").is(request.getCode())), PlanNewCommon.class)
                 .switchIfEmpty(Mono.error(new BaseException("计划code异常 返回结果为空")))
-                .onErrorResume(throwable -> Mono.error(new Exception(LogExceptionStackTrace.erroStackTrace(throwable).toString())));
+                .onErrorResume(throwable -> Mono.error(new BaseException("计划code异常 返回结果为空")));
         Mono<PlanNewCommonMaterialRes> materialResMono = planNewCommonMono.flatMap(plan -> {
             // 群音频
             Mono<Audio> groupAudio = this.getAudio(request.getAudioId());
@@ -438,7 +436,7 @@ public class PlanNewCommonOutController {
                 returnLoop = template.selectOne(Query.query(Criteria.where("id").is(request.getReturnLoopId())
                                 .and("deleted_at").isNull()), ReturnLoop.class)
                         .switchIfEmpty(Mono.just(getReturnLoop()))
-                        .onErrorResume(throwable -> Mono.error(new Exception(LogExceptionStackTrace.erroStackTrace(throwable).toString())));
+                        .onErrorResume(throwable -> Mono.error(new BaseException("查询返回广告异常:::" + throwable.getMessage())));
             }
             // 分享背景组
             Mono<List<BackgroupImageItem>> backgroupImageItemMono;
@@ -448,17 +446,17 @@ public class PlanNewCommonOutController {
                 backgroupImageItemMono = template.select(Query.query(Criteria
                                 .where("group_id").is(request.getBackgroundGroupId())), BackgroupImageItem.class).collectList()
                         .switchIfEmpty(Mono.just(List.of()))
-                        .onErrorResume(throwable -> Mono.error(new Exception(LogExceptionStackTrace.erroStackTrace(throwable).toString())));
+                        .onErrorResume(throwable -> Mono.error(new BaseException("查询分享背景组异常:::" + throwable.getMessage())));
             }
-            Mono<TakeawayH5Data> takeaway ;
+            Mono<TakeawayH5Data> takeaway;
             if (Objects.nonNull(request.getTakeawayId()) && request.getTakeawayId() > 0) {
                 takeaway = takeawayServicesInterface.getTakeaway(request.getTakeawayId())
                         .switchIfEmpty(Mono.just(new TakeawayH5Data()))
-                        .onErrorResume(e->Mono.error(new BaseException("查询外卖模版数据异常:::"+LogExceptionStackTrace.erroStackTrace(e).toString())));
-            }else {
-                takeaway=Mono.just(new TakeawayH5Data());
+                        .onErrorResume(e -> Mono.error(new BaseException("查询外卖模版数据异常:::" + e.getMessage())));
+            } else {
+                takeaway = Mono.just(new TakeawayH5Data());
             }
-            return Mono.zip(groupAudio, retAudio, returnLoop, backgroupImageItemMono,takeaway).flatMap(f -> {
+            return Mono.zip(groupAudio, retAudio, returnLoop, backgroupImageItemMono, takeaway).flatMap(f -> {
                 PlanNewCommonMaterialRes materialRes = new PlanNewCommonMaterialRes();
                 materialRes.setGroupAudio(f.getT1());
                 materialRes.setRetAudio(f.getT2());
@@ -528,7 +526,7 @@ public class PlanNewCommonOutController {
         }
         Mono<PlanNewCommon> planNewCommonMono = template.selectOne(Query.query(Criteria.where("code").is(request.getCode())), PlanNewCommon.class)
                 .switchIfEmpty(Mono.error(new BaseException(" code错误")))
-                .onErrorResume(throwable -> Mono.error(new Exception(LogExceptionStackTrace.erroStackTrace(throwable).toString())));
+                .onErrorResume(throwable -> Mono.error(new BaseException("code错误::" + throwable.getMessage())));
         Mono<PlanNewCommonShareRes> resMono = planNewCommonMono.flatMap(plan -> {
             Mono<StringBuilder> stringBuilderMono;
             boolean isQs = Objects.nonNull(request.getWx_user_id()) && !request.getWx_user_id().isEmpty();
@@ -568,7 +566,7 @@ public class PlanNewCommonOutController {
                             int v = userVisits % qs.size();
                             res.setQsSetting(qs.get(v));
                             if (f.getT6().toString().isEmpty()) {
-                                throw new BaseException("计划链接 查询匹配域名为空");
+                                return Mono.error(new BaseException("计划链接 查询匹配域名为空"));
                             }
                             res.setLink(f.getT6().toString());
                         } else {
@@ -590,7 +588,7 @@ public class PlanNewCommonOutController {
                             int v = userVisits % fx.size();
                             res.setFxSetting(fx.get(v));
                             if (f.getT6().toString().isEmpty()) {
-                                throw new BaseException("计划链接 查询匹配域名为空");
+                                return Mono.error(new BaseException("计划链接 查询匹配域名为空"));
                             }
                             res.setLink(f.getT6().toString());
                         } else {
@@ -644,7 +642,7 @@ public class PlanNewCommonOutController {
                 try {
                     jsonObject1 = JSONUtil.parseObj(ret);
                 } catch (Exception e) {
-                    throw new BaseException(e.getMessage() + "---" + JSONUtil.parseObj(goRequest) + " error:" + LogExceptionStackTrace.erroStackTrace(e).toString());
+                    return Mono.error(new Exception(e.getMessage() + "---" + JSONUtil.parseObj(goRequest) + " error:" + LogExceptionStackTrace.erroStackTrace(e).toString()));
                 }
                 if (jsonObject1.containsKey("code") && jsonObject1.get("code", Integer.class) == 0 && jsonObject1.containsKey("data")) {
                     JSONObject data = jsonObject1.get("data", JSONObject.class);
@@ -672,7 +670,8 @@ public class PlanNewCommonOutController {
         try {
             jsonObject = JSONUtil.parseObj(posterTemplate);
         } catch (Exception e) {
-            throw new BaseException(e.getMessage() + "---" + posterTemplate + " error:" + LogExceptionStackTrace.erroStackTrace(e).toString());
+            log.error(e.getMessage() + "---" + posterTemplate + " error:" + LogExceptionStackTrace.erroStackTrace(e).toString());
+            return null;
         }
         // JSONObject jsonObject = JSONUtil.parseObj(posterTemplate);
         GoRequest goRequest = new GoRequest();
@@ -718,7 +717,7 @@ public class PlanNewCommonOutController {
             try {
                 jsonObject = JSONUtil.parseObj(posterTemplate);
             } catch (Exception e) {
-                throw new BaseException(e.getMessage() + "---" + posterTemplate + " error:" + LogExceptionStackTrace.erroStackTrace(e).toString());
+                return Mono.error(new Exception(e.getMessage() + "---" + posterTemplate + " error:" + LogExceptionStackTrace.erroStackTrace(e).toString()));
             }
             GoRequest goRequest = new GoRequest();
             BeanUtil.copyProperties(jsonObject, goRequest);

+ 8 - 3
launch-admin/src/main/java/com/webflux/launchadmin/mysql/service/planNew/goGenerate/GoGenerateService.java

@@ -22,6 +22,7 @@ import com.webflux.launchadmin.mysql.service.planNew.structure.GoRequest;
 import com.webflux.launchadmin.mysql.service.planNew.structure.Item;
 import com.webflux.launchcommon.returnObj.RStatus;
 import jakarta.annotation.Resource;
+import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.data.r2dbc.core.R2dbcEntityTemplate;
 import org.springframework.data.relational.core.query.Criteria;
@@ -42,7 +43,7 @@ import java.util.*;
 import java.util.stream.Collectors;
 import java.util.stream.Stream;
 
-
+@Slf4j
 @Service
 public class GoGenerateService {
 
@@ -56,21 +57,25 @@ public class GoGenerateService {
     // http://wx-share-8.duiweize.com 正式
     public String goGenerate(String temStr) {
         String body = "";
+        String url = value + "/api/image/createImage";
         try {
-            body = HttpUtil.post(value + "/api/image/createImage", temStr, 100000);
+            body = HttpUtil.post(url, temStr, 100000);
             return body;
         } catch (Exception e) {
+            log.error("error: body:::" + body + ":::request:::" + temStr + ", url: {}", url, e);
             throw new BaseException(e.getMessage() + "body:::" + body + ":::request:::" + temStr);
         }
     }
 
     public String goGenerateStr(String temStr) {
         String body = "";
+        String url = value + "/api/image/createImage";
         try {
-            body = HttpUtil.post(value + "/api/image/createImage", temStr, 100000);
+            body = HttpUtil.post(url, temStr, 100000);
             JSONUtil.parseObj(body);
             return body;
         } catch (Exception e) {
+            log.error("error: body:::" + body + ":::request:::" + temStr + ", url: {}", url, e);
             throw new BaseException(e.getMessage() + "body:::" + body);
         }
 

+ 1 - 1
launch-admin/src/main/resources/application.yml

@@ -6,7 +6,7 @@ spring:
     name: launch-webflux
   profiles:
     # 环境配置
-    active: dev
+    active: test
 
 
 xxl:

+ 15 - 16
launch-common/src/main/java/com/webflux/launchcommon/returnObj/RW.java

@@ -33,19 +33,19 @@ public class RW<T> implements Serializable {
     private T data;
 
     public static <T> Mono<RW<T>> fail(Mono<T> monoData) {
-        return createR(ERR, ERR_MSG,monoData);
+        return createR(ERR, ERR_MSG, monoData);
     }
 
-    public static <T> Mono<RW<T>> fail(String message,Mono<T> monoData) {
+    public static <T> Mono<RW<T>> fail(String message, Mono<T> monoData) {
         return createR(ERR, message, monoData);
     }
 
-    public static <T> Mono<RW<T>> fail(String code, String message,Mono<T> monoData) {
-        return createR(code, message,monoData);
+    public static <T> Mono<RW<T>> fail(String code, String message, Mono<T> monoData) {
+        return createR(code, message, monoData);
     }
 
-    public static <T> Mono<RW<T>> success(String message,Mono<T> monoData) {
-        return createR(OK, message,monoData);
+    public static <T> Mono<RW<T>> success(String message, Mono<T> monoData) {
+        return createR(OK, message, monoData);
     }
 
     public static <T> Mono<RW<T>> success(Mono<T> monoData) {
@@ -53,15 +53,14 @@ public class RW<T> implements Serializable {
     }
 
 
-
-   private static <T> Mono<RW<T>> createR(String code, String msg, Mono<T> monoData){
-      return monoData.map(data->{
-           final RW rw = new RW();
-           rw.setData(data);
-           rw.setCode(code);
-           rw.setMsg(msg);
-           return rw;
-       });
+    private static <T> Mono<RW<T>> createR(String code, String msg, Mono<T> monoData) {
+        return monoData.map(data -> {
+            final RW rw = new RW();
+            rw.setData(data);
+            rw.setCode(code);
+            rw.setMsg(msg);
+            return rw;
+        });
 
     }
 
@@ -80,7 +79,7 @@ public class RW<T> implements Serializable {
         this.data = result;
     }
 
-    public boolean isSuccess(){
+    public boolean isSuccess() {
         return OK.equals(code);
     }