Skip to content

Add logs in wiki data edit and session refresh flow #1874

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 3, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -233,17 +233,27 @@ public String getEditToken() throws IOException {

@Override
public String getCentralAuthToken() throws IOException {
String centralAuthToken = api.action("centralauthtoken")
.get()
.getString("/api/centralauthtoken/@centralauthtoken");
CustomApiResult result = api.action("centralauthtoken").get();
String centralAuthToken = result.getString("/api/centralauthtoken/@centralauthtoken");

Timber.d("MediaWiki Central auth token is %s", centralAuthToken);

if(centralAuthToken == null || centralAuthToken.isEmpty()) {
if ((centralAuthToken == null || centralAuthToken.isEmpty())
&& "notLoggedIn".equals(result.getString("api/error/@code"))) {
Timber.d("Central auth token isn't valid. Trying to fetch a fresh token");
api.removeAllCookies();
String login = login(AccountUtil.getUserName(context), AccountUtil.getPassword(context));
if(login.equals("PASS")) {
String loginResultCode = login(AccountUtil.getUserName(context), AccountUtil.getPassword(context));
if(loginResultCode.equals("PASS")) {
return getCentralAuthToken();
} else if(loginResultCode.equals("2FA")) {
Timber.e("Cannot refresh session for 2FA enabled user. Login required");
} else {
Timber.e("Error occurred in refreshing session. Error code is %s", loginResultCode);
}
} else {
Timber.e("Error occurred while fetching auth token. Error code is %s and message is %s",
result.getString("api/error/@code"),
result.getString("api/error/@info"));
}
return centralAuthToken;
}
Expand Down Expand Up @@ -467,13 +477,12 @@ public boolean addWikidataEditTag(String revisionId) throws IOException {
return false;
}

Node node = result.getNode("api").getDocument();
Element element = (Element) node;

if (element != null && element.getAttribute("status").equals("success")) {
if ("success".equals(result.getString("api/tag/result/@status"))) {
return true;
} else {
Timber.e(result.getString("api/error/@code") + " " + result.getString("api/error/@info"));
Timber.e("Error occurred in creating claim. Error code is: %s and message is %s",
result.getString("api/error/@code"),
result.getString("api/error/@info"));
}
return false;
}
Expand Down