Commit 3c27ecf5 authored by Adrien Dorsaz's avatar Adrien Dorsaz

Tries to fix connection exception.

parent 01c833ec
......@@ -52,32 +52,46 @@ public class ArticleListGetter extends
try {
articles = getArticles(toDisplay[0]);
} catch (GetArticleListException e) {
// TODO Pass to offline mode
Log.e(SessionManager.LOG_SERVER,
"Cannot get article list, are you correctly logged ? Remove cookie and try again. Using saved data if available.");
e.printStackTrace();
Editor editor = mActivity.getSharedPreferences(
SettingsActivity.SHARED_PREFERENCES, Activity.MODE_PRIVATE)
.edit();
editor.remove(SessionManager.SESSION_COOKIE_SETTINGS);
editor.commit();
articles = null;
} catch (ParseArticleException e) {
// TODO Make Toast
Log.e(SessionManager.LOG_SERVER,
"Cannot parse JSON response. Trying to display already parsed articles. Please contact developpers.");
"Cannot parse JSON response when getting articles. Please contact developpers.");
e.printStackTrace();
articles = null;
} catch (ConnectException e) {
// TODO Pass to offline mode
Log.e(SessionManager.LOG_SERVER,
"There was an error with network connection. Removing cookie to try again later. Using saved data if available.");
"There was an error with network connection.");
setCookiePref(null);
e.printStackTrace();
articles = null;
} catch (GetArticleListException e) {
// Try again login and request.
SessionManager.deleteSessionCookie();
try {
articles = getArticles(toDisplay[0]);
} catch (ConnectException e1) {
// TODO Pass to offline mode
Log.e(SessionManager.LOG_SERVER,
"There was an error with network connection.");
setCookiePref(null);
e1.printStackTrace();
articles = null;
} catch (ParseArticleException e1) {
// TODO Make Toast
Log.e(SessionManager.LOG_SERVER,
"Cannot parse JSON response when getting articles. Please contact developpers.");
e1.printStackTrace();
articles = null;
} catch (GetArticleListException e1) {
// TODO Didn't resolved the error. Stop it.
Log.e(SessionManager.LOG_SERVER,
"Cannot get article list, always bad response from server (twice tested).");
e1.printStackTrace();
articles = null;
}
}
return articles;
}
......@@ -91,7 +105,7 @@ public class ArticleListGetter extends
} else {
Toast.makeText(
mActivity,
"Unable to get rss feeds. Have you network connection ? Are your settings correct ?",
"Unable to get rss feeds. Please check your network and settings.",
Toast.LENGTH_LONG).show();
}
}
......
......@@ -40,20 +40,31 @@ public class ArticleReadStateUpdater extends
protected Article doInBackground(Article... article) {
try {
article[0] = updateArticle(article[0]);
} catch (ReadStateUpdateException e) {
// TODO Manage exception
Log.e(SessionManager.LOG_SERVER,
"Error while updating. Try again later");
e.printStackTrace();
article[0] = null;
} catch (ConnectException e) {
// TODO Auto-generated catch block
Log.e(SessionManager.LOG_SERVER,
"There was an error with network connection. Removing cookie to try again later. Using saved data if available.");
"There was an error with network connection.");
e.printStackTrace();
article[0] = null;
} catch (ReadStateUpdateException e) {
// Try again login and request.
SessionManager.deleteSessionCookie();
try {
article[0] = updateArticle(article[0]);
} catch (ConnectException e1) {
// TODO Auto-generated catch block
Log.e(SessionManager.LOG_SERVER,
"There was an error with network connection.");
e1.printStackTrace();
article[0] = null;
} catch (ReadStateUpdateException e1) {
Log.e(SessionManager.LOG_SERVER,
"Error while updating read state twice. Try again later");
e1.printStackTrace();
article[0] = null;
}
}
return article[0];
......
......@@ -40,19 +40,31 @@ public class ArticleStarredStateUpdater extends
protected Article doInBackground(Article... article) {
try {
article[0] = updateArticle(article[0]);
} catch (StarredStateUpdateException e) {
Log.e(SessionManager.LOG_SERVER,
"Error while updating starred state. Try again later.");
e.printStackTrace();
article[0] = null;
} catch (ConnectException e) {
// TODO Auto-generated catch block
Log.e(SessionManager.LOG_SERVER,
"There was an error with network connection. Removing cookie to try again later. Using saved data if available.");
"There was an error with network connection.");
e.printStackTrace();
article[0] = null;
} catch (StarredStateUpdateException e) {
// Try again login and request.
SessionManager.deleteSessionCookie();
try {
article[0] = updateArticle(article[0]);
} catch (ConnectException e1) {
// TODO Auto-generated catch block
Log.e(SessionManager.LOG_SERVER,
"There was an error with network connection.");
e1.printStackTrace();
article[0] = null;
} catch (StarredStateUpdateException e1) {
Log.e(SessionManager.LOG_SERVER,
"Error while updating starred state twice. Try again later.");
e1.printStackTrace();
article[0] = null;
}
}
return article[0];
......@@ -66,7 +78,7 @@ public class ArticleStarredStateUpdater extends
} else {
Toast.makeText(
mActivity,
"Unable to update rss feed. Have you network connection ? Are your settings correct ?",
"Unable to update starred state for an article. Please check your network and settings.",
Toast.LENGTH_LONG).show();
}
}
......
......@@ -70,6 +70,15 @@ public class SessionManager {
return doRequest(pageUrl, httpParameters);
}
static protected void deleteSessionCookie() {
mSessionCookie = null;
Editor editor = mApplicationContext.getSharedPreferences(
SettingsActivity.SHARED_PREFERENCES, Activity.MODE_PRIVATE)
.edit();
editor.remove(SessionManager.SESSION_COOKIE_SETTINGS);
editor.commit();
}
private void loginLounge() throws ConnectException {
try {
String urlParameters = LOGIN_GET_RSSLOUNGE + "="
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment