package com.fdkankan.common.exception;

import com.fdkankan.common.constant.CameraConstant;
import com.fdkankan.common.constant.ErrorCode;
import com.fdkankan.common.constant.ServerCode;
import lombok.Data;

/**
 * 自定义业务异常类
 */
@Data
public class BusinessException extends RuntimeException {
    private int code;
    private String message;

    public BusinessException(ErrorCode errorCode){
        this.code = errorCode.code();
        this.message = errorCode.message();
    }
    public BusinessException(ServerCode serverCode){
        this.code = serverCode.code();
        this.message = serverCode.message();
    }
    public BusinessException(CameraConstant errorCode){
        this.code = errorCode.code();
        this.message = errorCode.message();
    }
    public BusinessException(int code, String msg){
        this.code = code;
        this.message = msg;
    }
    public BusinessException(ServerCode serverCode, Object...args){
        this.code = serverCode.code();
        this.message = serverCode.formatMessage(args);
    }

    public BusinessException(ErrorCode errorCode, Object...args){
        this.code = errorCode.code();
        this.message = errorCode.formatMessage(args);
    }
}
