com.hannesdorfmann.httpkit.exception.HttpExceptionChecker Maven / Gradle / Ivy
package com.hannesdorfmann.httpkit.exception;
import org.apache.http.NoHttpResponseException;
import org.apache.http.conn.ConnectTimeoutException;
import org.apache.http.conn.ConnectionPoolTimeoutException;
/**
* This class can be used to determine the reason for a given exception
*
* @author Hannes Dorfmann
*
*/
public class HttpExceptionChecker {
/**
* Tries to determine, if the thrown Exception has been thrown because the
* server is not reachable. This is not a guarantee that the server is down
* or does not response because of heavy load. It's possible that the users
* Internet connection goes off while establishing the connection to the
* server and has caused a exception that would be typically thrown, when
* the server is not reachable
*
* @param e
* The exception
* @return true, if server may be down, otherwise false
*/
public static boolean isServerNotReachable(Exception e) {
return (e instanceof NoHttpResponseException)
|| (e instanceof ConnectTimeoutException)
|| (e instanceof ConnectionPoolTimeoutException);
}
/**
* Determines if the Exception is a {@link NoInternetConnectionException}.
* That means, that the user has definitely not an active internet
* connection.
*
* @param e
* @return true, if exception is instance of
* {@link NoInternetConnectionException}
*/
public static boolean isNoInternetConnection(Exception e) {
return e instanceof NoInternetConnectionException;
}
/**
* This method will be thrown, if the http status code was unexpected, and a
* {@link UnexpectedHttpStatusCodeException} was thrown
*
* @param e
* @return ture if exception is instance of
* {@link UnexpectedHttpStatusCodeException}
*/
public static boolean isUnexpectesStatusCode(Exception e) {
return e instanceof UnexpectedHttpStatusCodeException;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy