package hr.com.port.ips.eracun.service;

public class EracunErrors {	
	
	private EracunErrors() {}

    public static boolean isTimeout(Throwable t) {
        if (t == null) return false;
        if (t instanceof java.net.SocketTimeoutException) return true; // connect/read/write timeout
        // OkHttp može wrapati u InterruptedIOException; provjeri cause chain
        if (t instanceof java.io.InterruptedIOException && t.getCause() instanceof java.net.SocketTimeoutException) {
            return true;
        }
        Throwable c = t.getCause();
        while (c != null && c != t) {
            if (c instanceof java.net.SocketTimeoutException) return true;
            c = c.getCause();
        }
        return false;
    }

    public static boolean isNetworkUnavailable(Throwable t) {
        // još par tipičnih transijentnih mrežnih
        return (t instanceof java.net.ConnectException)
            || (t instanceof java.net.UnknownHostException)
            || (t instanceof javax.net.ssl.SSLHandshakeException)
            || (t instanceof javax.net.ssl.SSLException)
            || isTimeout(t);
    }	
}