package com.github.wxiaoqi.security.common.exception;

import com.github.wxiaoqi.security.common.constant.RestCode;
import com.github.wxiaoqi.security.common.util.process.ResultCode;

import java.util.Map;
import java.util.Set;

/**
 * Created by ace on 2017/9/8.
 */
public class BaseException extends RuntimeException {
    private int status = 200;
    private String subCode;
    public int getStatus() {
        return status;
    }

    public void setStatus(int status) {
        this.status = status;
    }

    public String getSubCode() {
        return subCode;
    }

    public void setSubCode(String subCode) {
        this.subCode = subCode;
    }

    public BaseException() {
    }

    public BaseException(String message,int status) {
        super(message);
        this.status = status;
    }

    public BaseException(String message,String subCode){
        super(message);
        this.status=400;
        this.subCode = subCode;
    }

    public BaseException(String message) {
        super(message);
    }

    public BaseException(String message, Throwable cause) {
        super(message, cause);
    }

    public BaseException(Throwable cause) {
        super(cause);
    }

    public BaseException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
        super(message, cause, enableSuppression, writableStackTrace);
    }

    public BaseException(RestCode restCode) {
        super(restCode.getMsg());
        this.status = restCode.getStatus();
    }

    public BaseException(int code) {
        super(ResultCode.getMsg(code));
        this.status = code;
    }

    public BaseException(int code, Map<String, Object> map) {
        super(ResultCode.getMsg(code) + (map == null? "" : map.toString()));
        this.status = code;
    }

    public BaseException(int code, Set<String> set) {
        super(ResultCode.getMsg(code)+ (set == null? "" : set.toString()));
        this.status = code;
    }
}
