mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-26 20:33:53 +01:00
Fixes #4601 - 1. Handle possible exceptions in upload file from stash 2. Modify MWException, as error is nullable, update getTitle and getMessage to rever that (#4627)
This commit is contained in:
parent
553a1d983e
commit
9238a208ba
4 changed files with 25 additions and 10 deletions
|
|
@ -218,13 +218,13 @@ public class UploadClient {
|
|||
CommonsApplication.DEFAULT_EDIT_SUMMARY,
|
||||
uniqueFileName,
|
||||
fileKey).map(uploadResponse -> {
|
||||
UploadResponse uploadResult = gson
|
||||
final UploadResponse uploadResult = gson
|
||||
.fromJson(uploadResponse, UploadResponse.class);
|
||||
if (uploadResult.getUpload() == null) {
|
||||
final MwException exception = gson
|
||||
.fromJson(uploadResponse, MwException.class);
|
||||
Timber.e(exception, "Error in uploading file from stash");
|
||||
throw new RuntimeException(exception.getErrorCode());
|
||||
throw new Exception(exception.getErrorCode());
|
||||
}
|
||||
return uploadResult.getUpload();
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1,3 +1,3 @@
|
|||
package fr.free.nrw.commons.upload
|
||||
|
||||
class UploadResponse(val upload: UploadResult)
|
||||
class UploadResponse(val upload: UploadResult?)
|
||||
|
|
@ -21,6 +21,7 @@ import fr.free.nrw.commons.contributions.ContributionDao
|
|||
import fr.free.nrw.commons.di.ApplicationlessInjection
|
||||
import fr.free.nrw.commons.location.LatLng
|
||||
import fr.free.nrw.commons.media.MediaClient
|
||||
import fr.free.nrw.commons.upload.StashUploadResult
|
||||
import fr.free.nrw.commons.upload.StashUploadState
|
||||
import fr.free.nrw.commons.upload.UploadClient
|
||||
import fr.free.nrw.commons.upload.UploadResult
|
||||
|
|
@ -265,7 +266,9 @@ class UploadWorker(var appContext: Context, workerParams: WorkerParameters) :
|
|||
//Upload the file to stash
|
||||
val stashUploadResult = uploadClient.uploadFileToStash(
|
||||
appContext, filename, contribution, notificationProgressUpdater
|
||||
).blockingSingle()
|
||||
).onErrorReturn{
|
||||
return@onErrorReturn StashUploadResult(StashUploadState.FAILED,fileKey = null)
|
||||
}.blockingSingle()
|
||||
|
||||
when (stashUploadResult.state) {
|
||||
StashUploadState.SUCCESS -> {
|
||||
|
|
@ -278,9 +281,11 @@ class UploadWorker(var appContext: Context, workerParams: WorkerParameters) :
|
|||
//Upload the file from stash
|
||||
val uploadResult = uploadClient.uploadFileFromStash(
|
||||
contribution, uniqueFileName, stashUploadResult.fileKey
|
||||
).blockingSingle()
|
||||
).onErrorReturn {
|
||||
return@onErrorReturn null
|
||||
}.blockingSingle()
|
||||
|
||||
if (uploadResult.isSuccessful()) {
|
||||
if (null != uploadResult && uploadResult.isSuccessful()) {
|
||||
Timber.d(
|
||||
"Stash Upload success..proceeding to make wikidata edit"
|
||||
)
|
||||
|
|
@ -313,6 +318,7 @@ class UploadWorker(var appContext: Context, workerParams: WorkerParameters) :
|
|||
Timber.e("Upload from stash failed for contribution : $filename")
|
||||
showFailedNotification(contribution)
|
||||
contribution.state=Contribution.STATE_FAILED
|
||||
contributionDao.saveSynchronous(contribution)
|
||||
if (STASH_ERROR_CODES.contains(exception.message)) {
|
||||
clearChunks(contribution)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,11 +31,20 @@ public class MwException extends RuntimeException {
|
|||
return error;
|
||||
}
|
||||
|
||||
@Nullable public String getTitle() {
|
||||
@Nullable
|
||||
public String getTitle() {
|
||||
if (error != null) {
|
||||
return error.getTitle();
|
||||
}
|
||||
return errors != null ? errors.get(0).getTitle() : null;
|
||||
}
|
||||
|
||||
@Override @Nullable public String getMessage() {
|
||||
@Override
|
||||
@Nullable
|
||||
public String getMessage() {
|
||||
if (error != null) {
|
||||
return error.getDetails();
|
||||
}
|
||||
return errors != null ? errors.get(0).getDetails() : null;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue