Merge pull request #4245 from ByteHamster/better-feed-errors

Better parser errors
This commit is contained in:
H. Lehmann 2020-06-19 09:46:50 +02:00 committed by GitHub
commit bc0b7a705a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 17 deletions

View File

@ -49,10 +49,7 @@ public class FeedParserTask implements Callable<FeedHandlerResult> {
try {
result = feedHandler.parseFeed(feed);
Log.d(TAG, feed.getTitle() + " parsed");
if (!checkFeedData(feed)) {
throw new InvalidFeedException();
}
checkFeedData(feed);
} catch (SAXException | IOException | ParserConfigurationException e) {
successful = false;
e.printStackTrace();
@ -95,23 +92,17 @@ public class FeedParserTask implements Callable<FeedHandlerResult> {
/**
* Checks if the feed was parsed correctly.
*/
private boolean checkFeedData(Feed feed) {
private void checkFeedData(Feed feed) throws InvalidFeedException {
if (feed.getTitle() == null) {
Log.e(TAG, "Feed has no title.");
return false;
throw new InvalidFeedException("Feed has no title");
}
if (!hasValidFeedItems(feed)) {
Log.e(TAG, "Feed has invalid items");
return false;
}
return true;
checkFeedItems(feed);
}
private boolean hasValidFeedItems(Feed feed) {
private void checkFeedItems(Feed feed) throws InvalidFeedException {
for (FeedItem item : feed.getItems()) {
if (item.getTitle() == null) {
Log.e(TAG, "Item has no title");
return false;
throw new InvalidFeedException("Item has no title: " + item);
}
if (item.getPubDate() == null) {
Log.e(TAG, "Item has no pubDate. Using current time as pubDate");
@ -121,7 +112,6 @@ public class FeedParserTask implements Callable<FeedHandlerResult> {
item.setPubDate(new Date());
}
}
return true;
}
public DownloadStatus getDownloadStatus() {

View File

@ -6,6 +6,7 @@ package de.danoeh.antennapod.core.util;
public class InvalidFeedException extends Exception {
private static final long serialVersionUID = 1L;
public InvalidFeedException() {
public InvalidFeedException(String message) {
super(message);
}
}