Skip to content

Commit ce4a0c1

Browse files
committed
Display possible solution for badtoken error
1 parent 5b25229 commit ce4a0c1

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

app/src/main/java/fr/free/nrw/commons/mwapi/ApacheHttpClientMediaWikiApi.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
import fr.free.nrw.commons.BuildConfig;
4545
import fr.free.nrw.commons.Media;
4646
import fr.free.nrw.commons.PageTitle;
47+
import fr.free.nrw.commons.R;
4748
import fr.free.nrw.commons.achievements.FeedbackResponse;
4849
import fr.free.nrw.commons.auth.AccountUtil;
4950
import fr.free.nrw.commons.category.CategoryImageUtils;
@@ -52,6 +53,7 @@
5253
import fr.free.nrw.commons.notification.NotificationUtils;
5354
import fr.free.nrw.commons.utils.ContributionUtils;
5455
import fr.free.nrw.commons.utils.DateUtils;
56+
import fr.free.nrw.commons.utils.ViewUtil;
5557
import in.yuvi.http.fluent.Http;
5658
import io.reactivex.Observable;
5759
import io.reactivex.Single;
@@ -79,6 +81,8 @@ public class ApacheHttpClientMediaWikiApi implements MediaWikiApi {
7981
private Gson gson;
8082
private final OkHttpClient okHttpClient;
8183

84+
private final String ERROR_CODE_BAD_TOKEN = "badtoken";
85+
8286
public ApacheHttpClientMediaWikiApi(Context context,
8387
String apiURL,
8488
String wikidatApiURL,
@@ -898,8 +902,11 @@ public UploadResult uploadFile(String filename,
898902

899903
if (!resultStatus.equals("Success")) {
900904
String errorCode = result.getString("/api/error/@code");
901-
Log.d("deneme","error code: "+errorCode);
902905
Timber.e(errorCode);
906+
907+
if (errorCode.equals(ERROR_CODE_BAD_TOKEN)) {
908+
ViewUtil.showLongToast(context, R.string.bad_token_error_proposed_solution);
909+
}
903910
return new UploadResult(resultStatus, errorCode);
904911
} else {
905912
// If success we have to remove file from temp directory

app/src/main/res/values/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -434,5 +434,6 @@ Upload your first media by touching the camera or gallery icon above.</string>
434434
<string name="display_location_permission_explanation">Ask for location permission when needed for nearby notification card view feature.</string>
435435

436436
<string name="this_function_needs_network_connection">This function requires network connection, please check your connection settings.</string>
437+
<string name="bad_token_error_proposed_solution">Upload failed with "badtoken" error. Logging out and in again usually help to solve this issue. Meanwhile, we are working to prevent this error. </string>
437438

438439
</resources>

0 commit comments

Comments
 (0)