package com.ssyf.common.web.error;


import com.ssyf.common.web.apicode.IApiCode;

/**
 * 业务中断运行时异常
 * 无需捕获，由全局异常统一处理
 *
 * @author huwei
 * @date 2022/7/5 15:37
 */
public class ServiceRuntimeException extends RuntimeException implements ServiceError {

    private String code;

    public ServiceRuntimeException(String code, String message) {
        super(message);
        this.code = code;
    }

    public static ServiceRuntimeException instance(IApiCode apiCode) {
        return instance(apiCode.getCode(), apiCode.getMessage());
    }

    public static ServiceRuntimeException instance(String code, String message) {
        return new ServiceRuntimeException(code, message);
    }

    public static void throw0(IApiCode apiCode){
        throw0(apiCode.getCode() , apiCode.getMessage());
    }

    public static void throw0(String code, String message) {
        throw instance(code, message);
    }

    @Override
    public String getCode() {
        return this.code;
    }
}
