1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
|
public enum StatusCodeDict {
COMMON_OK(0, "ok"), COMMON_UNKNOWN(9999, "未知的异常"), COMMON_INVALID_REQUEST(9998, "无效的请求"),
SYSTEM_404(404, "404你懂的"), SYSTEM_502(502, "服务器打洋了"), SYSTEM_500(500, "哎哟,这里有个锅"),
PARAM(1001, "参数错误"), PARAM_BEYOND_QUANTITY_NUMBER(1003, "参数错误,超出最大数量限制"),
PARAM_LOGIN_ERROR(1102, "用户名不存在或密码错误"),
GOODS_IS_NOT_EXISTED(1301, "商品不存在"), GOODS_IS_NOT_MARKETABLE(1302, "商品已经下架"),
DB(1401, "数据库异常"),
UNDEFINED(1999, "未定义的业务异常"), ;
private int code; private String msg; private static final Map<Integer, StatusCodeDict> dict = new HashMap<>();
static { Arrays.stream(StatusCodeDict.values()) .forEach(p -> dict.put(p.code, p)); }
public static StatusCodeDict of(int code) { return Optional.of(dict.get(code)).orElse(COMMON_UNKNOWN); }
StatusCodeDict(int code, String msg) { this.code = code; this.msg = msg; }
public int code() { return code; }
public String msg() { return msg; } }
|