/*
 * Decompiled with CFR 0.152.
 */
package org.jeecg.common.enums;

import lombok.Getter;

@Getter
public enum SentinelErrorInfoEnum {
    FlowException("访问频繁，请稍候再试"),
    ParamFlowException("热点参数限流"),
    SystemBlockException("系统规则限流或降级"),
    AuthorityException("授权规则不通过"),
    UnknownError("未知异常"),
    DegradeException("服务降级");

    String error;
    Integer code;

    public void setError(String error) {
        this.error = error;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    SentinelErrorInfoEnum(String error, Integer code) {
        this.error = error;
        this.code = code;
    }

    SentinelErrorInfoEnum(String error) {
        this.error = error;
        this.code = 500;
    }

    public static SentinelErrorInfoEnum getErrorByException(Throwable throwable) {
        if (throwable == null) {
            return null;
        }
        String exceptionClass = throwable.getClass().getSimpleName();
        for (SentinelErrorInfoEnum e : SentinelErrorInfoEnum.values()) {
            if (!exceptionClass.equals(e.name())) continue;
            return e;
        }
        return null;
    }
}