package com.stm.asset.http;

import org.apache.http.conn.ConnectTimeoutException;

import java.net.SocketTimeoutException;

/**
 * 类名称：HttpException
 * 类描述：请求异常封装
 * 创建人：story
 * 创建时间：2021-12-14 14:56
 */
public class HttpException extends Exception {
    private static final long serialVersionUID = -4699234082428363296L;

    private int exceptionCode;
    private Throwable throwable;

    public HttpException() {}

    public HttpException(String detailMessage) {
        super(detailMessage);
    }

    public HttpException(String detailMessage, Throwable throwable) {
        super(detailMessage, throwable);
        this.throwable =throwable;
    }

    public HttpException(Throwable throwable) {
        super(throwable);
        this.throwable =throwable;
    }

    public HttpException(int exceptionCode) {
        this.exceptionCode = exceptionCode;
    }

    public HttpException(int exceptionCode, String detailMessage) {
        super(detailMessage);
        this.exceptionCode = exceptionCode;
    }

    public HttpException(int exceptionCode, String detailMessage, Throwable throwable) {
        super(detailMessage, throwable);
        this.exceptionCode = exceptionCode;
        this.throwable =throwable;
    }

    public HttpException(int exceptionCode, Throwable throwable) {
        super(throwable);
        this.exceptionCode = exceptionCode;
        this.throwable =throwable;
    }

    public int getExceptionCode() {
        return exceptionCode;
    }

    public boolean isConnectTimeout(){
        if (this.throwable instanceof ConnectTimeoutException || this.throwable instanceof SocketTimeoutException) {
            return true;
        }
        return false;
    }

    public Throwable getThrowable() {
        return throwable;
    }

}
