package com.bc.exam.core.exception;

import com.bc.exam.core.api.ApiError;
import com.bc.exam.core.api.ApiRest;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * @Description 描述:服务自定义异常 继承运行时异常
 * @Author A贾宇婷034244310
 * @Date 20260615
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class ServiceException extends RuntimeException{

    /**
     * 错误码
     */
    private Integer code;

    /**
     * 错误消息
     */
    private String msg;

    /**
     * 从结果初始化
     * @param apiRest
     */
    public ServiceException(ApiRest apiRest){
        this.code = apiRest.getCode();
        this.msg = apiRest.getMsg();
    }

    /**
     * 从枚举中获取参数
     * @param apiError
     */
    public ServiceException(ApiError apiError){
        this.code = apiError.getCode();
        this.msg = apiError.msg;
    }

    /**
     * 异常构造
     * @param msg
     */
    public ServiceException(String msg){
        this.code = 1;
        this.msg = msg;
    }

}
