mirror of
https://gitee.com/binary/weixin-java-tools.git
synced 2025-10-14 18:25:10 +08:00
为WxError加入builder模式支持
This commit is contained in:
@@ -5,8 +5,7 @@ import me.chanjar.weixin.common.util.json.WxGsonBuilder;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 微信错误码说明
|
||||
* http://mp.weixin.qq.com/wiki/index.php?title=全局返回码说明
|
||||
* 微信错误码说明,请阅读: <a href="http://mp.weixin.qq.com/wiki/10/6380dc743053a91c544ffd2b7c959166.html">全局返回码说明</a>
|
||||
* @author Daniel Qian
|
||||
*
|
||||
*/
|
||||
@@ -54,4 +53,30 @@ public class WxError implements Serializable {
|
||||
return "微信错误: errcode=" + errorCode + ", errmsg=" + errorMsg + "\njson:" + json;
|
||||
}
|
||||
|
||||
public static Builder newBuilder(){
|
||||
return new Builder();
|
||||
}
|
||||
|
||||
public static class Builder{
|
||||
private int errorCode;
|
||||
private String errorMsg;
|
||||
|
||||
public Builder setErrorCode(int errorCode) {
|
||||
this.errorCode = errorCode;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setErrorMsg(String errorMsg) {
|
||||
this.errorMsg = errorMsg;
|
||||
return this;
|
||||
}
|
||||
|
||||
public WxError build(){
|
||||
WxError wxError = new WxError();
|
||||
wxError.setErrorCode(this.errorCode);
|
||||
wxError.setErrorMsg(this.errorMsg);
|
||||
return wxError;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@@ -483,9 +483,8 @@ public class WxMpServiceImpl implements WxMpService {
|
||||
try {
|
||||
return String.format(url, URLEncoder.encode(ticket, Charsets.UTF_8.name()));
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
WxError error = new WxError();
|
||||
error.setErrorCode(-1);
|
||||
error.setErrorMsg(e.getMessage());
|
||||
WxError error = WxError.newBuilder().setErrorCode(-1)
|
||||
.setErrorMsg(e.getMessage()).build();
|
||||
throw new WxErrorException(error);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user