Throw out reading actions that will never succeed.

This commit is contained in:
dosiecki 2015-02-13 02:38:59 -08:00
parent d593279559
commit 3f1d5fe471
2 changed files with 24 additions and 1 deletions

View file

@ -2,6 +2,9 @@ package com.newsblur.network.domain;
import android.util.Log;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* A generic response to an API call that only encapsuates success versus failure.
*/
@ -13,6 +16,8 @@ public class NewsBlurResponse {
public ResponseErrors errors;
public long readTime;
public static final Pattern KnownUserErrors = Pattern.compile("cannot mark as unread");
public boolean isError() {
if ((message != null) && (!message.equals(""))) {
Log.d(this.getClass().getName(), "Response interpreted as error due to 'message' field: " + message);
@ -25,6 +30,20 @@ public class NewsBlurResponse {
return false;
}
// TODO: can we add a canonical flag of some sort to 100% of API responses that differentiates
// between 400-type and 2/3/500-type errors? Until then, we have to sniff known bad ones.
public boolean isUserError() {
if (message != null) {
Matcher m = KnownUserErrors.matcher(message);
if (m.find()) return true;
}
if ((errors != null) && (errors.message.length > 0) && (errors.message[0] != null)) {
Matcher m = KnownUserErrors.matcher(errors.message[0]);
if (m.find()) return true;
}
return false;
}
/**
* Gets the error message returned by the API, or defaultMessage if none was found.
*/

View file

@ -307,7 +307,11 @@ public class NBSyncService extends Service {
// if we attempted a call and it failed, do not mark the action as done
if (response != null) {
if (response.isError()) {
continue actionsloop;
if (response.isUserError()) {
Log.d(this.getClass().getName(), "Discarding reading action with user error.");
} else {
continue actionsloop;
}
}
}