package com.brilliance.isc.exception;


import lombok.Getter;
import lombok.Setter;
import org.apache.commons.io.IOUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.PrintStream;


/**
 * 公共异常类
 *
 
 */
@Getter
@Setter
public class SSTFException extends RestBizException {

    private static final long serialVersionUID = -8997686356234975400L;

    private static Logger logger = LoggerFactory.getLogger(SSTFException.class);

    private String errorCod;
    private String errorMsg;

    public SSTFException(String errorCod, String errorMsg, Throwable e) {
        super(errorCod,errorMsg);
        this.errorMsg = errorMsg;
        this.errorCod = errorCod;
        super.initCause(e);

    }

    public SSTFException(String errorCod, String errorMsg) {
        super(errorCod,errorMsg);
        this.errorMsg = errorMsg;
        this.errorCod = errorCod;

    }

    public static String getExceptionDetail(Exception ex) {
        String ret = "";
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        PrintStream pout = new PrintStream(out);
        try {
            ex.printStackTrace(pout);
            ret = new String(out.toByteArray());
            IOUtils.closeQuietly(pout);
            IOUtils.closeQuietly(out);
        } catch (Exception e) {
            pout.close();
            try {
                out.close();
            } catch (IOException exc) {
                logger.error(e.getMessage());
            }

        }
        return ret;
    }
}

