mirror of
https://gitee.com/binary/weixin-java-tools.git
synced 2025-10-15 10:45:15 +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;
|
import java.io.Serializable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 微信错误码说明
|
* 微信错误码说明,请阅读: <a href="http://mp.weixin.qq.com/wiki/10/6380dc743053a91c544ffd2b7c959166.html">全局返回码说明</a>
|
||||||
* http://mp.weixin.qq.com/wiki/index.php?title=全局返回码说明
|
|
||||||
* @author Daniel Qian
|
* @author Daniel Qian
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@@ -54,4 +53,30 @@ public class WxError implements Serializable {
|
|||||||
return "微信错误: errcode=" + errorCode + ", errmsg=" + errorMsg + "\njson:" + json;
|
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 {
|
try {
|
||||||
return String.format(url, URLEncoder.encode(ticket, Charsets.UTF_8.name()));
|
return String.format(url, URLEncoder.encode(ticket, Charsets.UTF_8.name()));
|
||||||
} catch (UnsupportedEncodingException e) {
|
} catch (UnsupportedEncodingException e) {
|
||||||
WxError error = new WxError();
|
WxError error = WxError.newBuilder().setErrorCode(-1)
|
||||||
error.setErrorCode(-1);
|
.setErrorMsg(e.getMessage()).build();
|
||||||
error.setErrorMsg(e.getMessage());
|
|
||||||
throw new WxErrorException(error);
|
throw new WxErrorException(error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user