package com.judong.chuanyiserver.exception;

import com.judong.chuanyiserver.enums.ResultEnum;
import lombok.Data;

@Data
public class CustomException extends RuntimeException {
    private Integer code;

    /**
     * 通过状态码和错误消息创建异常对象
     *
     * @param message
     * @param code
     */
    public CustomException(Integer code, String message) {
        super(message);
        this.code = code;
    }

    /**
     * 接收枚举类型对象
     *
     * @param resultEnum
     */
    public CustomException(ResultEnum resultEnum) {
        super(resultEnum.getRespMsg());
        this.code = resultEnum.getRespCode();
    }

    @Override
    public String toString() {
        return "CustomException{" +
                "code=" + code +
                ", message=" + this.getMessage() +
                '}';
    }

}
