diff --git a/clients/android/NewsBlur/src/com/newsblur/network/domain/NewsBlurResponse.java b/clients/android/NewsBlur/src/com/newsblur/network/domain/NewsBlurResponse.java index ddd46536d..5bc485787 100644 --- a/clients/android/NewsBlur/src/com/newsblur/network/domain/NewsBlurResponse.java +++ b/clients/android/NewsBlur/src/com/newsblur/network/domain/NewsBlurResponse.java @@ -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. */ diff --git a/clients/android/NewsBlur/src/com/newsblur/service/NBSyncService.java b/clients/android/NewsBlur/src/com/newsblur/service/NBSyncService.java index aed3a6448..1ed0480ea 100644 --- a/clients/android/NewsBlur/src/com/newsblur/service/NBSyncService.java +++ b/clients/android/NewsBlur/src/com/newsblur/service/NBSyncService.java @@ -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; + } } }