1
zj
2024-06-13 a4662cc65a02f258062bf6cc392ceb1017db9292
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
/*
 * Copyright (c) 2018-2999 广州市蓝海创新科技有限公司 All rights reserved.
 *
 * https://www.mall4j.com/
 *
 * 未经允许,不可做商业用途!
 *
 * 版权所有,侵权必究!
 */
 
package com.yami.trading.common.enums;
 
/**
 * 与前端进行特殊交互需要使用的状态码,由于小程序需要,所以状态码只能为3位数字,并且不能与正常的http状态码冲突
 * @author LGH
 */
public enum YamiHttpStatus {
    /**
     * 客户端看到401状态码时,应该重新登陆
     */
    UNAUTHORIZED(401, "未授权"),
 
    COUPONCANNOTUSETOGETHER(601, "优惠券不能共用"),
 
    SOCIAL_ACCOUNT_NOT_BIND(475, "social account not bind"),
    ACCOUNT_NOT_REGISTER(476, "account not register"),
    ;
 
 
    private final int value;
 
    private final String msg;
 
 
    YamiHttpStatus(int value, String msg) {
        this.value = value;
        this.msg = msg;
    }
 
 
    /**
     * Return the integer value of this status code.
     */
    public int value() {
        return this.value;
    }
 
    /**
     * Return the msg of this status code.
     */
    public String getMsg() {
        return msg;
    }
 
    /**
     * Return a string representation of this status code.
     */
    @Override
    public String toString() {
        return this.value + " " + name();
    }
 
 
    public static YamiHttpStatus valueOf(int statusCode) {
        YamiHttpStatus status = resolve(statusCode);
        if (status == null) {
            throw new IllegalArgumentException("没有找到该Http状态码包含状态 [" + statusCode + "]");
        }
        return status;
    }
 
    public static YamiHttpStatus resolve(int statusCode) {
        for (YamiHttpStatus status : values()) {
            if (status.value == statusCode) {
                return status;
            }
        }
        return null;
    }
 
 
}