package org.forks.jsonrpc;

public final class JsonRpcException extends Exception {
    public boolean isNetworkError(){
        return mCode == NETWORK_ERROR_CODE;
    }
    static int NETWORK_ERROR_CODE = -1;

    private static final long serialVersionUID = -3409287525569584913L;
    private int mCode = 0;
    private String mTrace;

    public JsonRpcException() {
        super();
    }

    public JsonRpcException(String message, Throwable throwable) {
        super(message, throwable);
    }

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

    public JsonRpcException(Throwable throwable) {
        super(throwable);
    }

    public JsonRpcException(int code, String message) {
        this(code, message, null);
    }

    public JsonRpcException(int code, String message, String trace) {
        super(message);
        mCode = code;
        mTrace = trace;
    }

    public int getCode() {
        return mCode;
    }

    public boolean is5xxError() {
        return mCode >= 500 && mCode < 600;
    }

    public String getDetailMessage() {
        return mTrace;
    }

}
