package com.qmth.boot.core.exception;

/**
 * 禁止访问的运行时异常，在API层会按403状态码处理
 */
public class ForbiddenException extends RuntimeException implements CodeNameException {

    private static final long serialVersionUID = 1014093321734424324L;

    private Integer code;

    private String name;

    public ForbiddenException(String message) {
        super(message);
    }

    public ForbiddenException(String message, Throwable t) {
        super(message, t);
    }

    /**
     * 带所有参数的构造方法
     *
     * @param code    - 数字标识，范围在100~999
     * @param name    - 异常详细类型
     * @param message - 文字提示
     * @param cause   - 触发来源
     */
    public ForbiddenException(Integer code, String name, String message, Throwable cause) {
        super(message, cause);
        if (code != null) {
            if (code < 100 || code > 999) {
                throw new IllegalArgumentException("ForbiddenException.code should between 100~999");
            }
        }
        this.code = code;
        this.name = name;
    }

    public Integer getCode() {
        return code;
    }

    public String getName() {
        return name;
    }
}
