mirror of
https://github.com/Athou/commafeed.git
synced 2026-03-21 21:37:29 +00:00
propagate exception message
This commit is contained in:
@@ -110,7 +110,7 @@ public class HttpGetter {
|
|||||||
response = client.execute(httpget);
|
response = client.execute(httpget);
|
||||||
int code = response.getStatusLine().getStatusCode();
|
int code = response.getStatusLine().getStatusCode();
|
||||||
if (code == HttpStatus.SC_NOT_MODIFIED) {
|
if (code == HttpStatus.SC_NOT_MODIFIED) {
|
||||||
throw new NotModifiedException();
|
throw new NotModifiedException("304 http code");
|
||||||
} else if (code >= 300) {
|
} else if (code >= 300) {
|
||||||
throw new HttpResponseException(code,
|
throw new HttpResponseException(code,
|
||||||
"Server returned HTTP error code " + code);
|
"Server returned HTTP error code " + code);
|
||||||
@@ -118,7 +118,7 @@ public class HttpGetter {
|
|||||||
|
|
||||||
} catch (HttpResponseException e) {
|
} catch (HttpResponseException e) {
|
||||||
if (e.getStatusCode() == HttpStatus.SC_NOT_MODIFIED) {
|
if (e.getStatusCode() == HttpStatus.SC_NOT_MODIFIED) {
|
||||||
throw new NotModifiedException();
|
throw new NotModifiedException("304 http code");
|
||||||
} else {
|
} else {
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
@@ -131,13 +131,13 @@ public class HttpGetter {
|
|||||||
: lastModifiedHeader.getValue();
|
: lastModifiedHeader.getValue();
|
||||||
if (lastModified != null
|
if (lastModified != null
|
||||||
&& StringUtils.equals(lastModified, lastModifiedResponse)) {
|
&& StringUtils.equals(lastModified, lastModifiedResponse)) {
|
||||||
throw new NotModifiedException();
|
throw new NotModifiedException("lastModifiedHeader is the same");
|
||||||
}
|
}
|
||||||
|
|
||||||
String eTagResponse = eTagHeader == null ? null : eTagHeader
|
String eTagResponse = eTagHeader == null ? null : eTagHeader
|
||||||
.getValue();
|
.getValue();
|
||||||
if (eTag != null && StringUtils.equals(eTag, eTagResponse)) {
|
if (eTag != null && StringUtils.equals(eTag, eTagResponse)) {
|
||||||
throw new NotModifiedException();
|
throw new NotModifiedException("eTagHeader is the same");
|
||||||
}
|
}
|
||||||
|
|
||||||
HttpEntity entity = response.getEntity();
|
HttpEntity entity = response.getEntity();
|
||||||
@@ -217,6 +217,10 @@ public class HttpGetter {
|
|||||||
|
|
||||||
public static class NotModifiedException extends Exception {
|
public static class NotModifiedException extends Exception {
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
public NotModifiedException(String message){
|
||||||
|
super(message);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ public class FeedFetcher {
|
|||||||
if (lastContentHash != null && hash != null
|
if (lastContentHash != null && hash != null
|
||||||
&& lastContentHash.equals(hash)) {
|
&& lastContentHash.equals(hash)) {
|
||||||
log.debug("content hash not modified: {}", feedUrl);
|
log.debug("content hash not modified: {}", feedUrl);
|
||||||
throw new NotModifiedException();
|
throw new NotModifiedException("content hash not modified");
|
||||||
}
|
}
|
||||||
|
|
||||||
fetchedFeed = parser.parse(feedUrl, content);
|
fetchedFeed = parser.parse(feedUrl, content);
|
||||||
@@ -67,7 +67,7 @@ public class FeedFetcher {
|
|||||||
&& lastPublishedDate.getTime() == fetchedFeed.getFeed()
|
&& lastPublishedDate.getTime() == fetchedFeed.getFeed()
|
||||||
.getLastPublishedDate().getTime()) {
|
.getLastPublishedDate().getTime()) {
|
||||||
log.debug("publishedDate not modified: {}", feedUrl);
|
log.debug("publishedDate not modified: {}", feedUrl);
|
||||||
throw new NotModifiedException();
|
throw new NotModifiedException("publishedDate not modified");
|
||||||
}
|
}
|
||||||
|
|
||||||
Feed feed = fetchedFeed.getFeed();
|
Feed feed = fetchedFeed.getFeed();
|
||||||
|
|||||||
@@ -93,7 +93,7 @@ public class FeedParser {
|
|||||||
entry.setUrl(FeedUtils.truncate(
|
entry.setUrl(FeedUtils.truncate(
|
||||||
FeedUtils.toAbsoluteUrl(item.getLink(), feed.getLink()),
|
FeedUtils.toAbsoluteUrl(item.getLink(), feed.getLink()),
|
||||||
2048));
|
2048));
|
||||||
entry.setUpdated(validateDate(getEntryUpdateDate(item)));
|
entry.setUpdated(validateDate(getEntryUpdateDate(item), true));
|
||||||
entry.setAuthor(item.getAuthor());
|
entry.setAuthor(item.getAuthor());
|
||||||
|
|
||||||
FeedEntryContent content = new FeedEntryContent();
|
FeedEntryContent content = new FeedEntryContent();
|
||||||
@@ -111,7 +111,7 @@ public class FeedParser {
|
|||||||
entries.add(entry);
|
entries.add(entry);
|
||||||
}
|
}
|
||||||
Date lastEntryDate = null;
|
Date lastEntryDate = null;
|
||||||
Date publishedDate = validateDate(rss.getPublishedDate());
|
Date publishedDate = validateDate(rss.getPublishedDate(), false);
|
||||||
if (!entries.isEmpty()) {
|
if (!entries.isEmpty()) {
|
||||||
List<Long> sortedTimestamps = FeedUtils
|
List<Long> sortedTimestamps = FeedUtils
|
||||||
.getSortedTimestamps(entries);
|
.getSortedTimestamps(entries);
|
||||||
@@ -119,7 +119,7 @@ public class FeedParser {
|
|||||||
lastEntryDate = new Date(timestamp);
|
lastEntryDate = new Date(timestamp);
|
||||||
publishedDate = getFeedPublishedDate(publishedDate, entries);
|
publishedDate = getFeedPublishedDate(publishedDate, entries);
|
||||||
}
|
}
|
||||||
feed.setLastPublishedDate(publishedDate);
|
feed.setLastPublishedDate(validateDate(publishedDate, true));
|
||||||
feed.setAverageEntryInterval(FeedUtils
|
feed.setAverageEntryInterval(FeedUtils
|
||||||
.averageTimeBetweenEntries(entries));
|
.averageTimeBetweenEntries(entries));
|
||||||
feed.setLastEntryDate(lastEntryDate);
|
feed.setLastEntryDate(lastEntryDate);
|
||||||
@@ -160,12 +160,9 @@ public class FeedParser {
|
|||||||
|
|
||||||
private Date getFeedPublishedDate(Date publishedDate,
|
private Date getFeedPublishedDate(Date publishedDate,
|
||||||
List<FeedEntry> entries) {
|
List<FeedEntry> entries) {
|
||||||
if (publishedDate == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (FeedEntry entry : entries) {
|
for (FeedEntry entry : entries) {
|
||||||
if (entry.getUpdated().getTime() > publishedDate.getTime()) {
|
if (publishedDate == null || entry.getUpdated().getTime() > publishedDate.getTime()) {
|
||||||
publishedDate = entry.getUpdated();
|
publishedDate = entry.getUpdated();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -183,10 +180,10 @@ public class FeedParser {
|
|||||||
return date;
|
return date;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Date validateDate(Date date) {
|
private Date validateDate(Date date, boolean nullToNow) {
|
||||||
Date now = new Date();
|
Date now = new Date();
|
||||||
if (date == null) {
|
if (date == null) {
|
||||||
return now;
|
return nullToNow ? now : null;
|
||||||
}
|
}
|
||||||
if (date.before(START) || date.after(END)) {
|
if (date.before(START) || date.after(END)) {
|
||||||
return now;
|
return now;
|
||||||
|
|||||||
@@ -125,7 +125,7 @@ public class FeedRefreshWorker {
|
|||||||
feedRefreshUpdater.updateFeed(feed, entries);
|
feedRefreshUpdater.updateFeed(feed, entries);
|
||||||
|
|
||||||
} catch (NotModifiedException e) {
|
} catch (NotModifiedException e) {
|
||||||
log.debug("Feed not modified (304) : " + feed.getUrl());
|
log.debug("Feed not modified : {} - {}", feed.getUrl(), e.getMessage());
|
||||||
|
|
||||||
Date disabledUntil = null;
|
Date disabledUntil = null;
|
||||||
if (applicationSettingsService.get().isHeavyLoad()) {
|
if (applicationSettingsService.get().isHeavyLoad()) {
|
||||||
|
|||||||
Reference in New Issue
Block a user