mirror of
https://github.com/viq/NewsBlur.git
synced 2025-09-18 21:43:31 +00:00
Throw out reading actions that will never succeed.
This commit is contained in:
parent
d593279559
commit
3f1d5fe471
2 changed files with 24 additions and 1 deletions
|
@ -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.
|
||||
*/
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue