mirror of
https://github.com/Athou/commafeed.git
synced 2026-03-21 21:37:29 +00:00
Merge pull request #144 from kankri/master
Make subscription errors visible and avoid a NPE if the public URL is not set
This commit is contained in:
@@ -3,6 +3,7 @@ package com.commafeed.backend.services;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import javax.ejb.Stateless;
|
import javax.ejb.Stateless;
|
||||||
|
import javax.ejb.ApplicationException;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
|
||||||
import com.commafeed.backend.dao.FeedEntryDAO;
|
import com.commafeed.backend.dao.FeedEntryDAO;
|
||||||
@@ -19,6 +20,12 @@ import com.google.api.client.util.Lists;
|
|||||||
|
|
||||||
@Stateless
|
@Stateless
|
||||||
public class FeedSubscriptionService {
|
public class FeedSubscriptionService {
|
||||||
|
@ApplicationException
|
||||||
|
public class FeedSubscriptionException extends RuntimeException {
|
||||||
|
public FeedSubscriptionException(String msg) {
|
||||||
|
super(msg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
FeedService feedService;
|
FeedService feedService;
|
||||||
@@ -41,7 +48,12 @@ public class FeedSubscriptionService {
|
|||||||
public Feed subscribe(User user, String url, String title,
|
public Feed subscribe(User user, String url, String title,
|
||||||
FeedCategory category) {
|
FeedCategory category) {
|
||||||
|
|
||||||
if (url.startsWith(applicationSettingsService.get().getPublicUrl())) {
|
final String pubUrl = applicationSettingsService.get().getPublicUrl();
|
||||||
|
if (pubUrl == null) {
|
||||||
|
throw new FeedSubscriptionException(
|
||||||
|
"Public URL of this CommaFeed is unset");
|
||||||
|
}
|
||||||
|
if (url.startsWith(pubUrl)) {
|
||||||
throw new RuntimeException(
|
throw new RuntimeException(
|
||||||
"Could not subscribe to a feed from this CommaFeed instance");
|
"Could not subscribe to a feed from this CommaFeed instance");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -224,9 +224,15 @@ public class FeedREST extends AbstractResourceREST {
|
|||||||
FeedCategory category = CategoryREST.ALL.equals(req.getCategoryId()) ? null
|
FeedCategory category = CategoryREST.ALL.equals(req.getCategoryId()) ? null
|
||||||
: feedCategoryDAO.findById(Long.valueOf(req.getCategoryId()));
|
: feedCategoryDAO.findById(Long.valueOf(req.getCategoryId()));
|
||||||
FeedInfo info = (FeedInfo) fetchFeed(url).getEntity();
|
FeedInfo info = (FeedInfo) fetchFeed(url).getEntity();
|
||||||
feedSubscriptionService.subscribe(getUser(), info.getUrl(),
|
try {
|
||||||
|
feedSubscriptionService.subscribe(getUser(), info.getUrl(),
|
||||||
req.getTitle(), category);
|
req.getTitle(), category);
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.info("Failed to subscribe to URL {}: {}", url, e.getMessage());
|
||||||
|
return Response.status(Status.SERVICE_UNAVAILABLE).entity(
|
||||||
|
"Failed to subscribe to URL " + url + ": " + e.getMessage()
|
||||||
|
).build();
|
||||||
|
}
|
||||||
return Response.ok(Status.OK).build();
|
return Response.ok(Status.OK).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -75,8 +75,11 @@ function($scope, FeedService, CategoryService) {
|
|||||||
}
|
}
|
||||||
FeedService.subscribe($scope.sub, function() {
|
FeedService.subscribe($scope.sub, function() {
|
||||||
CategoryService.init();
|
CategoryService.init();
|
||||||
|
$scope.close();
|
||||||
|
}, function(data) {
|
||||||
|
$scope.state = 'failed';
|
||||||
|
$scope.sub.title = 'ERROR: ' + data.data;
|
||||||
});
|
});
|
||||||
$scope.close();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
$scope.openImport = function() {
|
$scope.openImport = function() {
|
||||||
|
|||||||
Reference in New Issue
Block a user