Expose all picoFeed errors to the Frontend when adding a subscription

This commit is contained in:
Mathias Kresin 2015-04-10 23:34:07 +02:00
parent 84ac8fc316
commit 1afb73b82d
13 changed files with 163 additions and 55 deletions

View File

@ -159,17 +159,50 @@ Router\action('subscribe', function() {
} }
$values += array('url' => trim($url), 'download_content' => 0, 'rtl' => 0, 'cloak_referrer' => 0); $values += array('url' => trim($url), 'download_content' => 0, 'rtl' => 0, 'cloak_referrer' => 0);
$feed_id = Model\Feed\create($values['url'], $values['download_content'], $values['rtl'], $values['cloak_referrer']);
if ($feed_id > 0) { try {
$feed_id = Model\Feed\create($values['url'], $values['download_content'], $values['rtl'], $values['cloak_referrer']);
}
catch (UnexpectedValueException $e) {
$error_message = t('This subscription already exists.');
}
catch (PicoFeed\Client\InvalidCertificateException $e) {
$error_message = t('Invalid SSL certificate.');
}
catch (PicoFeed\Client\InvalidUrlException $e) {
// picoFeed uses this exception for multiple reasons, but doesn't
// provide an exception code to distinguish what exactly happend here
$error_message = $e->getMessage();
}
catch (PicoFeed\Client\MaxRedirectException $e) {
$error_message = t('Maximum number of HTTP redirections exceeded.');
}
catch (PicoFeed\Client\MaxSizeException $e) {
$error_message = t('The content size exceeds to maximum allowed size.');
}
catch (PicoFeed\Client\TimeoutException $e) {
$error_message = t('Connection timeout.');
}
catch (PicoFeed\Parser\MalformedXmlException $e) {
$error_message = t('Feed is malformed.');
}
catch (PicoFeed\Reader\SubscriptionNotFoundException $e) {
$error_message = t('Unable to find a subscription.');
}
catch (PicoFeed\Reader\UnsupportedFeedFormatException $e) {
$error_message = t('Unable to detect the feed format.');
}
if (isset($feed_id) && $feed_id !== false) {
Session\flash(t('Subscription added successfully.')); Session\flash(t('Subscription added successfully.'));
Response\redirect('?action=feed-items&feed_id='.$feed_id); Response\redirect('?action=feed-items&feed_id='.$feed_id);
} }
else if ($feed_id === -2) {
Session\flash_error(t('This subscription already exists.'));
}
else { else {
Session\flash_error(t('Unable to find a subscription.')); if (! isset($error_message)) {
$error_message = t('Error occured.');
}
Session\flash_error($error_message);
} }
Response\html(Template\layout('add', array( Response\html(Template\layout('add', array(

View File

@ -3,6 +3,7 @@
require __DIR__.'/common.php'; require __DIR__.'/common.php';
use JsonRPC\Server; use JsonRPC\Server;
use PicoFeed\PicoFeedException;
$server = new Server; $server = new Server;
$server->authentication(array( $server->authentication(array(
@ -24,7 +25,16 @@ $server->register('feed.info', function ($feed_id) {
// Add a new feed // Add a new feed
$server->register('feed.create', function($url) { $server->register('feed.create', function($url) {
try {
$result = Model\Feed\create($url); $result = Model\Feed\create($url);
}
catch (PicoFeedException $e) {
$result = false;
}
catch (UnexpectedValueException $e) {
$result = false;
}
Model\Config\write_debug(); Model\Config\write_debug();
return $result; return $result;

View File

@ -231,4 +231,11 @@ return array(
'Original link marks article as read' => 'تحويل العنوان إلى مقروء بمجرد النقر على الرابط الأصلي للعنوان', 'Original link marks article as read' => 'تحويل العنوان إلى مقروء بمجرد النقر على الرابط الأصلي للعنوان',
'Cloak the image referrer' => 'Cloak the image referrer', 'Cloak the image referrer' => 'Cloak the image referrer',
// 'This subscription already exists.' => '', // 'This subscription already exists.' => '',
// 'Connection timeout.' => '',
// 'Error occured.' => '',
// 'Feed is malformed.' => '',
// 'Invalid SSL certificate.' => '',
// 'Maximum number of HTTP redirections exceeded.' => '',
// 'The content size exceeds to maximum allowed size.' => '',
// 'Unable to detect the feed format.' => '',
); );

View File

@ -231,4 +231,11 @@ return array(
'Original link marks article as read' => 'Původní odkaz označí článek za přečtený', 'Original link marks article as read' => 'Původní odkaz označí článek za přečtený',
'Cloak the image referrer' => 'Zamaskovat původce obrázků', 'Cloak the image referrer' => 'Zamaskovat původce obrázků',
// 'This subscription already exists.' => '', // 'This subscription already exists.' => '',
// 'Connection timeout.' => '',
// 'Error occured.' => '',
// 'Feed is malformed.' => '',
// 'Invalid SSL certificate.' => '',
// 'Maximum number of HTTP redirections exceeded.' => '',
// 'The content size exceeds to maximum allowed size.' => '',
// 'Unable to detect the feed format.' => '',
); );

View File

@ -231,4 +231,11 @@ return array(
// 'Original link marks article as read' => '', // 'Original link marks article as read' => '',
// 'Cloak the image referrer' => '', // 'Cloak the image referrer' => '',
// 'This subscription already exists.' => '', // 'This subscription already exists.' => '',
// 'Connection timeout.' => '',
// 'Error occured.' => '',
// 'Feed is malformed.' => '',
// 'Invalid SSL certificate.' => '',
// 'Maximum number of HTTP redirections exceeded.' => '',
// 'The content size exceeds to maximum allowed size.' => '',
// 'Unable to detect the feed format.' => '',
); );

View File

@ -231,4 +231,11 @@ return array(
'Original link marks article as read' => 'Link original marca artículo cómo leído', 'Original link marks article as read' => 'Link original marca artículo cómo leído',
// 'Cloak the image referrer' => '', // 'Cloak the image referrer' => '',
// 'This subscription already exists.' => '', // 'This subscription already exists.' => '',
// 'Connection timeout.' => '',
// 'Error occured.' => '',
// 'Feed is malformed.' => '',
// 'Invalid SSL certificate.' => '',
// 'Maximum number of HTTP redirections exceeded.' => '',
// 'The content size exceeds to maximum allowed size.' => '',
// 'Unable to detect the feed format.' => '',
); );

View File

@ -231,4 +231,11 @@ return array(
'Original link marks article as read' => 'Marquer les articles comme lu lors d\'un clic sur le lien original', 'Original link marks article as read' => 'Marquer les articles comme lu lors d\'un clic sur le lien original',
'Cloak the image referrer' => 'Falsifier le référent pour les images', 'Cloak the image referrer' => 'Falsifier le référent pour les images',
'This subscription already exists.' => 'Cet abonnement existe déjà.', 'This subscription already exists.' => 'Cet abonnement existe déjà.',
'Connection timeout.' => 'Connection timeout.',
'Error occured.' => 'Error occured.',
'Feed is malformed.' => 'Feed is malformed.',
'Invalid SSL certificate.' => 'Invalid SSL certificate.',
'Maximum number of HTTP redirections exceeded.' => 'Maximum number of HTTP redirections exceeded.',
'The content size exceeds to maximum allowed size.' => 'The content size exceeds to maximum allowed size.',
'Unable to detect the feed format.' => 'Unable to detect the feed format.',
); );

View File

@ -231,4 +231,11 @@ return array(
// 'Original link marks article as read' => '', // 'Original link marks article as read' => '',
// 'Cloak the image referrer' => '', // 'Cloak the image referrer' => '',
// 'This subscription already exists.' => '', // 'This subscription already exists.' => '',
// 'Connection timeout.' => '',
// 'Error occured.' => '',
// 'Feed is malformed.' => '',
// 'Invalid SSL certificate.' => '',
// 'Maximum number of HTTP redirections exceeded.' => '',
// 'The content size exceeds to maximum allowed size.' => '',
// 'Unable to detect the feed format.' => '',
); );

View File

@ -231,4 +231,11 @@ return array(
// 'Original link marks article as read' => '', // 'Original link marks article as read' => '',
// 'Cloak the image referrer' => '', // 'Cloak the image referrer' => '',
// 'This subscription already exists.' => '', // 'This subscription already exists.' => '',
// 'Connection timeout.' => '',
// 'Error occured.' => '',
// 'Feed is malformed.' => '',
// 'Invalid SSL certificate.' => '',
// 'Maximum number of HTTP redirections exceeded.' => '',
// 'The content size exceeds to maximum allowed size.' => '',
// 'Unable to detect the feed format.' => '',
); );

View File

@ -231,4 +231,11 @@ return array(
'Original link marks article as read' => 'Клик на оригиналну везу обележава чланак прочитаним', 'Original link marks article as read' => 'Клик на оригиналну везу обележава чланак прочитаним',
'Cloak the image referrer' => 'Прикривај рефератора слика', 'Cloak the image referrer' => 'Прикривај рефератора слика',
// 'This subscription already exists.' => '', // 'This subscription already exists.' => '',
// 'Connection timeout.' => '',
// 'Error occured.' => '',
// 'Feed is malformed.' => '',
// 'Invalid SSL certificate.' => '',
// 'Maximum number of HTTP redirections exceeded.' => '',
// 'The content size exceeds to maximum allowed size.' => '',
// 'Unable to detect the feed format.' => '',
); );

View File

@ -231,4 +231,11 @@ return array(
'Original link marks article as read' => 'Klik na originalnu vezu obeležava članak pročitanim', 'Original link marks article as read' => 'Klik na originalnu vezu obeležava članak pročitanim',
'Cloak the image referrer' => 'Prikrivaj referatora slika', 'Cloak the image referrer' => 'Prikrivaj referatora slika',
// 'This subscription already exists.' => '', // 'This subscription already exists.' => '',
// 'Connection timeout.' => '',
// 'Error occured.' => '',
// 'Feed is malformed.' => '',
// 'Invalid SSL certificate.' => '',
// 'Maximum number of HTTP redirections exceeded.' => '',
// 'The content size exceeds to maximum allowed size.' => '',
// 'Unable to detect the feed format.' => '',
); );

View File

@ -231,4 +231,11 @@ return array(
// 'Original link marks article as read' => '', // 'Original link marks article as read' => '',
// 'Cloak the image referrer' => '', // 'Cloak the image referrer' => '',
// 'This subscription already exists.' => '', // 'This subscription already exists.' => '',
// 'Connection timeout.' => '',
// 'Error occured.' => '',
// 'Feed is malformed.' => '',
// 'Invalid SSL certificate.' => '',
// 'Maximum number of HTTP redirections exceeded.' => '',
// 'The content size exceeds to maximum allowed size.' => '',
// 'Unable to detect the feed format.' => '',
); );

View File

@ -151,7 +151,8 @@ function import_opml($content)
// Add a new feed from an URL // Add a new feed from an URL
function create($url, $enable_grabber = false, $force_rtl = false, $cloak_referrer = false) function create($url, $enable_grabber = false, $force_rtl = false, $cloak_referrer = false)
{ {
try { $feed_id = false;
$db = Database::get('db'); $db = Database::get('db');
// Discover the feed // Discover the feed
@ -160,7 +161,7 @@ function create($url, $enable_grabber = false, $force_rtl = false, $cloak_referr
// Feed already there // Feed already there
if ($db->table('feeds')->eq('feed_url', $resource->getUrl())->count()) { if ($db->table('feeds')->eq('feed_url', $resource->getUrl())->count()) {
return -2; throw new \UnexpectedValueException;
} }
// Parse the feed // Parse the feed
@ -190,21 +191,15 @@ function create($url, $enable_grabber = false, $force_rtl = false, $cloak_referr
)); ));
if ($result) { if ($result) {
$feed_id = $db->getConnection()->getLastId(); $feed_id = $db->getConnection()->getLastId();
Item\update_all($feed_id, $feed->getItems()); Item\update_all($feed_id, $feed->getItems());
fetch_favicon($feed_id, $feed->getSiteUrl(), $feed->getIcon()); fetch_favicon($feed_id, $feed->getSiteUrl(), $feed->getIcon());
}
Config\write_debug(); Config\write_debug();
return (int) $feed_id; return $feed_id;
}
}
catch (PicoFeedException $e) {}
Config\write_debug();
return -1;
} }
// Refresh all feeds // Refresh all feeds