Handle errors in chunk uploads (#3899)

This commit is contained in:
Vivek Maskara 2020-08-17 04:43:36 -07:00 committed by GitHub
parent 1856196851
commit 74720aac19
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 99 additions and 14 deletions

View file

@ -2,15 +2,32 @@ package org.wikipedia.dataclient.mwapi;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import java.util.List;
public class MwException extends RuntimeException {
@SuppressWarnings("unused") @NonNull private final MwServiceError error;
@SuppressWarnings("unused") @Nullable private final MwServiceError error;
public MwException(@NonNull MwServiceError error) {
@SuppressWarnings("unused") @Nullable private final List<MwServiceError> errors;
public MwException(@Nullable MwServiceError error,
@Nullable final List<MwServiceError> errors) {
this.error = error;
this.errors = errors;
}
@NonNull public MwServiceError getError() {
@NonNull
public List<MwServiceError> getErrors() {
return errors;
}
public String getErrorCode() {
if(error!=null) {
return error.getCode();
}
return errors != null ? errors.get(0).getCode() : null;
}
@Nullable public MwServiceError getError() {
return error;
}

View file

@ -17,7 +17,7 @@ public abstract class MwResponse extends BaseModel implements PostProcessingType
@Override
public void postProcess() {
if (errors != null && !errors.isEmpty()) {
throw new MwException(errors.get(0));
throw new MwException(errors.get(0), errors);
}
}
}

View file

@ -13,6 +13,7 @@ import java.util.List;
* Gson POJO for a MediaWiki API error.
*/
public class MwServiceError extends BaseModel implements ServiceError {
@SuppressWarnings("unused") @Nullable private String code;
@SuppressWarnings("unused") @Nullable private String text;
@SuppressWarnings("unused") @Nullable private Data data;
@ -55,6 +56,11 @@ public class MwServiceError extends BaseModel implements ServiceError {
return null;
}
@Nullable
public String getCode() {
return code;
}
private static final class Data {
@SuppressWarnings("unused") @Nullable private List<Message> messages;