1 package com.foxinmy.weixin4j.exception;
2
3 import com.foxinmy.weixin4j.util.StringUtil;
4 import com.foxinmy.weixin4j.util.WeixinErrorUtil;
5
6
7
8
9
10
11
12
13
14
15 public class WeixinException extends Exception {
16
17 private static final long serialVersionUID = 7148145661883468514L;
18
19 private String code;
20 private String desc;
21
22 public WeixinException(String code, String desc) {
23 this.code = code;
24 this.desc = desc;
25 }
26
27 public WeixinException(String desc) {
28 this.code = "-1";
29 this.desc = desc;
30 }
31
32 public WeixinException(Throwable e) {
33 super(e);
34 }
35
36 public WeixinException(String message, Throwable cause) {
37 super(message, cause);
38 }
39
40 public String getErrorCode() {
41 return code;
42 }
43
44 public String getErrorDesc() {
45 return desc;
46 }
47
48 public String getErrorText() {
49 return WeixinErrorUtil.getText(code);
50 }
51
52 @Override
53 public String getMessage() {
54 if (StringUtil.isNotBlank(code)) {
55 StringBuilder buf = new StringBuilder();
56 buf.append(code).append(" >> ").append(desc);
57 String text = getErrorText();
58 if (StringUtil.isNotBlank(text)) {
59 buf.append(" >> ").append(text);
60 }
61 return buf.toString();
62 } else {
63 return super.getMessage();
64 }
65 }
66 }