package com.tuoheng.common.exception;

import com.tuoheng.common.common.ExceptionInterface;
import com.tuoheng.common.utils.JsonResult;
import lombok.Getter;
import lombok.Setter;

/**
 * @Author: 吴彬
 * @CreateTime: 2023-05-22  19:09
 * @Description: 业务异常类(业务处理时手动抛出异常)
 * @Version: 1.0
 */
@Getter
@Setter
public class ServiceException extends RuntimeException {

    static final long serialVersionUID = -7034897190745766938L;
    /**
     * 异常码
     */
    public int code;

    /**
     * 异常描述，兼容JsonResult
     */
    private String msg;


    /**
     * 构造器
     *
     * @param exceptionInfo
     */
    public ServiceException(ExceptionInterface exceptionInfo) {
        super(exceptionInfo.getMessage());
        this.msg = exceptionInfo.getMessage();
        this.code = exceptionInfo.getCode();
    }

    /**
     * 构造器
     *
     * @param code
     * @param msg
     */
    public ServiceException(int code, String msg) {
        super(msg);
        this.msg = msg;
        this.code = code;
    }

    /**
     * 构造器
     *
     * @param msg
     */
    public ServiceException(String msg) {
        super(msg);
        this.msg = msg;
        this.code = JsonResult.ERROR;
    }

}

