🎨 错误码中文含义匹配优化

This commit is contained in:
ichengzi 2022-01-20 12:05:12 +08:00 committed by GitHub
parent 31efa1ad66
commit 649af3e4bd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 44 additions and 29 deletions

View File

@ -1,7 +1,10 @@
package me.chanjar.weixin.common.error; package me.chanjar.weixin.common.error;
import com.google.common.collect.Maps;
import lombok.Getter; import lombok.Getter;
import java.util.Map;
/** /**
* <pre> * <pre>
* 企业微信全局错误码. * 企业微信全局错误码.
@ -1114,24 +1117,26 @@ public enum WxCpErrorMsgEnum {
*/ */
CODE_2000002(2000002, "CorpId参数无效指定的CorpId不存在"); CODE_2000002(2000002, "CorpId参数无效指定的CorpId不存在");
private int code; private final int code;
private String msg; private final String msg;
WxCpErrorMsgEnum(int code, String msg) { WxCpErrorMsgEnum(int code, String msg) {
this.code = code; this.code = code;
this.msg = msg; this.msg = msg;
} }
static final Map<Integer, String> valueMap = Maps.newHashMap();
static {
for (WxCpErrorMsgEnum value : WxCpErrorMsgEnum.values()) {
valueMap.put(value.code, value.msg);
}
}
/** /**
* 通过错误代码查找其中文含义.. * 通过错误代码查找其中文含义..
*/ */
public static String findMsgByCode(int code) { public static String findMsgByCode(int code) {
for (WxCpErrorMsgEnum value : WxCpErrorMsgEnum.values()) { return valueMap.getOrDefault(code, null);
if (value.code == code) {
return value.msg;
}
}
return null;
} }
} }

View File

@ -1,7 +1,10 @@
package me.chanjar.weixin.common.error; package me.chanjar.weixin.common.error;
import com.google.common.collect.Maps;
import lombok.Getter; import lombok.Getter;
import java.util.Map;
/** /**
* 微信小程序错误码 * 微信小程序错误码
* *
@ -664,16 +667,18 @@ public enum WxMaErrorMsgEnum {
this.msg = msg; this.msg = msg;
} }
static final Map<Integer, String> valueMap = Maps.newHashMap();
static {
for (WxMaErrorMsgEnum value : WxMaErrorMsgEnum.values()) {
valueMap.put(value.code, value.msg);
}
}
/** /**
* 通过错误代码查找其中文含义. * 通过错误代码查找其中文含义.
*/ */
public static String findMsgByCode(int code) { public static String findMsgByCode(int code) {
for (WxMaErrorMsgEnum value : WxMaErrorMsgEnum.values()) { return valueMap.getOrDefault(code, null);
if (value.code == code) {
return value.msg;
}
}
return null;
} }
} }

View File

@ -1,7 +1,10 @@
package me.chanjar.weixin.common.error; package me.chanjar.weixin.common.error;
import com.google.common.collect.Maps;
import lombok.Getter; import lombok.Getter;
import java.util.Map;
/** /**
* <pre> * <pre>
* 微信公众平台全局返回码. * 微信公众平台全局返回码.
@ -648,24 +651,26 @@ public enum WxMpErrorMsgEnum {
*/ */
CODE_45084(45084, "没有设置 speed 参数"); CODE_45084(45084, "没有设置 speed 参数");
private int code; private final int code;
private String msg; private final String msg;
WxMpErrorMsgEnum(int code, String msg) { WxMpErrorMsgEnum(int code, String msg) {
this.code = code; this.code = code;
this.msg = msg; this.msg = msg;
} }
static final Map<Integer, String> valueMap = Maps.newHashMap();
static {
for (WxMpErrorMsgEnum value : WxMpErrorMsgEnum.values()) {
valueMap.put(value.code, value.msg);
}
}
/** /**
* 通过错误代码查找其中文含义.. * 通过错误代码查找其中文含义..
*/ */
public static String findMsgByCode(int code) { public static String findMsgByCode(int code) {
for (WxMpErrorMsgEnum value : WxMpErrorMsgEnum.values()) { return valueMap.getOrDefault(code, null);
if (value.code == code) {
return value.msg;
}
}
return null;
} }
} }