mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-27 04:43:54 +01:00
Handle errors in chunk uploads (#3899)
This commit is contained in:
parent
1856196851
commit
74720aac19
8 changed files with 99 additions and 14 deletions
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue