package com.xxx.base.springframework.core.web.exception;

import lombok.Data;

/**
 * @description: 业务异常的封装
 * @author: huzhiwen
 * @create: 2019-01-26 17:50
 **/

@Data
public class ServiceException extends RuntimeException {
    private static final long serialVersionUID = 8075560915449741228L;
    private Integer code;

    private String errorMessage;

    public ServiceException(Integer code, String errorMessage) {
        super(errorMessage);
        this.code = code;
        this.errorMessage = errorMessage;
    }

    public ServiceException(AbstractBaseExceptionEnum exception) {
        super(exception.getMessage());
        code = exception.getCode();
        errorMessage = exception.getMessage();
    }

    public ServiceException(String errorMessage) {
        super(errorMessage);
        code = 500;
        this.errorMessage = errorMessage;
    }

    public ServiceException(String errorMessage, Object... stringFormat) {
        super(errorMessage);
        code = 500;
        this.errorMessage = String.format(errorMessage, stringFormat);
    }
}
