Skip to content

Commit 5b0022b

Browse files
committed
binarywang#595 优化WxPayException
1 parent f574403 commit 5b0022b

File tree

1 file changed

+23
-33
lines changed

1 file changed

+23
-33
lines changed

weixin-java-pay/src/main/java/com/github/binarywang/wxpay/exception/WxPayException.java

Lines changed: 23 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -2,41 +2,52 @@
22

33
import com.github.binarywang.wxpay.bean.result.BaseWxPayResult;
44
import com.google.common.base.Joiner;
5+
import lombok.Data;
6+
import lombok.EqualsAndHashCode;
57

68
/**
79
* <pre>
810
* 微信支付异常结果类
911
* Created by Binary Wang on 2017-6-6.
1012
* </pre>
13+
*
14+
* @author BinaryWang
1115
*/
16+
@Data
17+
@EqualsAndHashCode(callSuper = false)
1218
public class WxPayException extends Exception {
19+
private static final long serialVersionUID = 2214381471513460742L;
20+
21+
/**
22+
* 自定义错误讯息.
23+
*/
1324
private String customErrorMsg;
1425
/**
15-
* 返回状态码
26+
* 返回状态码.
1627
*/
1728
private String returnCode;
1829
/**
19-
* 返回信息
30+
* 返回信息.
2031
*/
2132
private String returnMsg;
2233

2334
/**
24-
* 业务结果
35+
* 业务结果.
2536
*/
2637
private String resultCode;
2738

2839
/**
29-
* 错误代码
40+
* 错误代码.
3041
*/
3142
private String errCode;
3243

3344
/**
34-
* 错误代码描述
45+
* 错误代码描述.
3546
*/
3647
private String errCodeDes;
3748

3849
/**
39-
* 微信支付返回的结果xml字符串
50+
* 微信支付返回的结果xml字符串.
4051
*/
4152
private String xmlString;
4253

@@ -60,6 +71,9 @@ private WxPayException(Builder builder) {
6071
xmlString = builder.xmlString;
6172
}
6273

74+
/**
75+
* 通过BaseWxPayResult生成异常对象.
76+
*/
6377
public static WxPayException from(BaseWxPayResult payBaseResult) {
6478
return WxPayException.newBuilder()
6579
.xmlString(payBaseResult.getXmlString())
@@ -71,30 +85,6 @@ public static WxPayException from(BaseWxPayResult payBaseResult) {
7185
.build();
7286
}
7387

74-
public String getXmlString() {
75-
return this.xmlString;
76-
}
77-
78-
public String getReturnCode() {
79-
return this.returnCode;
80-
}
81-
82-
public String getReturnMsg() {
83-
return this.returnMsg;
84-
}
85-
86-
public String getResultCode() {
87-
return this.resultCode;
88-
}
89-
90-
public String getErrCode() {
91-
return this.errCode;
92-
}
93-
94-
public String getErrCodeDes() {
95-
return this.errCodeDes;
96-
}
97-
9888
public static Builder newBuilder() {
9989
return new Builder();
10090
}
@@ -145,14 +135,14 @@ public WxPayException build() {
145135
}
146136

147137
public String buildErrorMsg() {
148-
return Joiner.on(",").skipNulls().join(new String[]{
138+
return Joiner.on(",").skipNulls().join(
149139
returnCode == null ? null : String.format("返回代码:[%s]", returnCode),
150140
returnMsg == null ? null : String.format("返回信息:[%s]", returnMsg),
151141
resultCode == null ? null : String.format("结果代码:[%s]", resultCode),
152142
errCode == null ? null : String.format("错误代码:[%s]", errCode),
153143
errCodeDes == null ? null : String.format("错误详情:[%s]", errCodeDes),
154-
xmlString == null ? null : "微信返回的原始报文:\n" + xmlString,
155-
});
144+
xmlString == null ? null : "微信返回的原始报文:\n" + xmlString
145+
);
156146
}
157147
}
158148
}

0 commit comments

Comments
 (0)