catch potential exception (timeout) when subscribing

This commit is contained in:
Athou
2013-07-02 10:14:47 +02:00
parent 31290aad8f
commit 761946d2a3

View File

@@ -6,6 +6,8 @@ import javax.ejb.ApplicationException;
import javax.inject.Inject; import javax.inject.Inject;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.commafeed.backend.dao.FeedEntryDAO; import com.commafeed.backend.dao.FeedEntryDAO;
import com.commafeed.backend.dao.FeedEntryStatusDAO; import com.commafeed.backend.dao.FeedEntryStatusDAO;
@@ -22,6 +24,8 @@ import com.google.api.client.util.Lists;
public class FeedSubscriptionService { public class FeedSubscriptionService {
private static Logger log = LoggerFactory.getLogger(FeedSubscriptionService.class);
@SuppressWarnings("serial") @SuppressWarnings("serial")
@ApplicationException @ApplicationException
public static class FeedSubscriptionException extends RuntimeException { public static class FeedSubscriptionException extends RuntimeException {
@@ -77,16 +81,20 @@ public class FeedSubscriptionService {
feedSubscriptionDAO.saveOrUpdate(sub); feedSubscriptionDAO.saveOrUpdate(sub);
if (newSubscription) { if (newSubscription) {
List<FeedEntryStatus> statuses = Lists.newArrayList(); try {
List<FeedEntry> allEntries = feedEntryDAO.findByFeed(feed, 0, 10); List<FeedEntryStatus> statuses = Lists.newArrayList();
for (FeedEntry entry : allEntries) { List<FeedEntry> allEntries = feedEntryDAO.findByFeed(feed, 0, 10);
FeedEntryStatus status = new FeedEntryStatus(); for (FeedEntry entry : allEntries) {
status.setEntry(entry); FeedEntryStatus status = new FeedEntryStatus();
status.setRead(false); status.setEntry(entry);
status.setSubscription(sub); status.setRead(false);
statuses.add(status); status.setSubscription(sub);
statuses.add(status);
}
feedEntryStatusDAO.saveOrUpdate(statuses);
} catch (Exception e) {
log.error("could not fetch initial statuses when importing {} : {}", feed.getUrl(), e.getMessage());
} }
feedEntryStatusDAO.saveOrUpdate(statuses);
} }
taskGiver.add(feed); taskGiver.add(feed);
return feed; return feed;