From 1eec14831cd317de82fa21f506ca08f9e8fd7253 Mon Sep 17 00:00:00 2001 From: qaiu <736226400@qq.com> Date: Thu, 10 Aug 2023 01:42:34 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E7=BB=93=E6=9E=84=E4=BC=98?= =?UTF-8?q?=E5=8C=96;=E4=BF=AE=E5=A4=8D123pan=E8=A7=A3=E6=9E=90=E9=94=99?= =?UTF-8?q?=E8=AF=AF=E7=9A=84=E9=97=AE=E9=A2=98#9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cn/qaiu/lz/common/parser/PanBase.java | 57 +++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 web-service/src/main/java/cn/qaiu/lz/common/parser/PanBase.java diff --git a/web-service/src/main/java/cn/qaiu/lz/common/parser/PanBase.java b/web-service/src/main/java/cn/qaiu/lz/common/parser/PanBase.java new file mode 100644 index 0000000..2948120 --- /dev/null +++ b/web-service/src/main/java/cn/qaiu/lz/common/parser/PanBase.java @@ -0,0 +1,57 @@ +package cn.qaiu.lz.common.parser; + +import cn.qaiu.vx.core.util.VertxHolder; +import io.vertx.core.Handler; +import io.vertx.core.Promise; +import io.vertx.ext.web.client.WebClient; +import io.vertx.ext.web.client.WebClientOptions; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public abstract class PanBase { + protected Logger log = LoggerFactory.getLogger(this.getClass()); + + protected Promise promise = Promise.promise(); + + protected WebClient client = WebClient.create(VertxHolder.getVertxInstance()); + protected WebClient clientNoRedirects = WebClient.create(VertxHolder.getVertxInstance(), OPTIONS); + private static final WebClientOptions OPTIONS = new WebClientOptions().setFollowRedirects(false); + + + protected String key; + protected String pwd; + + protected PanBase(String key, String pwd) { + this.key = key; + this.pwd = pwd; + } + + protected void fail(Throwable t, String errorMsg, Object... args) { + try { + String s = String.format(errorMsg.replaceAll("\\{}", "%s"), args); + log.error("解析异常: " + s, t.fillInStackTrace()); + promise.fail(this.getClass().getSimpleName() + ": 解析异常: " + s + " -> " + t); + } catch (Exception e) { + log.error("ErrorMsg format fail. The parameter has been discarded", e); + log.error("解析异常: " + errorMsg, t.fillInStackTrace()); + promise.fail(this.getClass().getSimpleName() + ": 解析异常: " + errorMsg + " -> " + t); + } + } + + protected void fail(String errorMsg, Object... args) { + try { + String s = String.format(errorMsg.replaceAll("\\{}", "%s"), args); + log.error("解析异常: " + s); + promise.fail(this.getClass().getSimpleName() + " - 解析异常: " + s); + } catch (Exception e) { + log.error("ErrorMsg format fail. The parameter has been discarded", e); + log.error("解析异常: " + errorMsg); + promise.fail(this.getClass().getSimpleName() + " - 解析异常: " + errorMsg); + } + } + + protected Handler handleFail(String errorMsg) { + return t -> fail(this.getClass().getSimpleName() + " - 请求异常 {}: -> {}", errorMsg, t.fillInStackTrace()); + } + +}