Reputation: 2468
I am having error in handling the timeout exception in asynchttpclient
@Override
public void onFailure(int statusCode, Header[] headers, byte[] responseBody, Throwable error) {
closeProgressDialog();
Log.e("DB", String.valueOf(error));
Log.e("DB", String.valueOf(error.getCause() instanceof ConnectTimeoutException));
}
first log gives the response cz.msebera.android.httpclient.conn.ConnectTimeoutException: Connect to /192.168.0.107:80 timed out
while second log gives null
or false
I want to handle the timeout exception how should I do it?
Upvotes: 1
Views: 1545
Reputation: 470
I suggest to increase the timeout
client.setTimeout(15000);
then override all onFailure methods.
@Override
public void onFailure(Throwable error, String content) {
if ( error.getCause() instanceof ConnectTimeoutException ) {
System.out.println("Connection timeout !");
}
}
i hope this will solve the issue
Upvotes: 0
Reputation: 10259
Your 2nd log operation is based on
error.getCause()
which is null or not a ConnectTimeoutException
, while within your first log operation you are directly using the Throwable
given in method parameter.
Therefore, I would suggest to use the error
and not error.getCause()
to handle the ConnectTimeoutException
.
Log.e("DB", String.valueOf(error instanceof ConnectTimeoutException)); // --> Should be true now
Upvotes: 2