From b35e703294615456334fc37cb325ffa9d191276b Mon Sep 17 00:00:00 2001 From: Bernhard Posselt Date: Sat, 26 Mar 2016 20:18:19 +0100 Subject: split up exception handling into a separate method --- fetcher/feedfetcher.php | 65 +++++++++++++++++++++++++++---------------------- 1 file changed, 36 insertions(+), 29 deletions(-) diff --git a/fetcher/feedfetcher.php b/fetcher/feedfetcher.php index 458f1220d..18f0f8093 100644 --- a/fetcher/feedfetcher.php +++ b/fetcher/feedfetcher.php @@ -13,6 +13,8 @@ namespace OCA\News\Fetcher; +use Exception; + use PicoFeed\Parser\MalFormedXmlException; use PicoFeed\Reader\Reader; use PicoFeed\Parser\Parser; @@ -121,38 +123,43 @@ class FeedFetcher implements IFeedFetcher { return [$feed, $items]; - } catch(\Exception $ex){ - $msg = $ex->getMessage(); - - if ($ex instanceof MalFormedXmlException) { - $msg = $this->l10n->t('Feed contains invalid XML'); - } else if ($ex instanceof SubscriptionNotFoundException) { - $msg = $this->l10n->t('Feed not found: either the website ' . - 'does not provide a feed or blocks access. To rule out ' . - 'blocking, try to download the feed on your server\'s ' . - 'command line using curl: curl http://the-feed.tld'); - } else if ($ex instanceof UnsupportedFeedFormatException) { - $msg = $this->l10n->t('Detected feed format is not supported'); - } else if ($ex instanceof InvalidCertificateException) { - $msg = $this->l10n->t('SSL Certificate is invalid'); - } else if ($ex instanceof InvalidUrlException) { - $msg = $this->l10n->t('Website not found'); - } else if ($ex instanceof MaxRedirectException) { - $msg = $this->l10n->t('More redirects than allowed, aborting'); - } else if ($ex instanceof MaxSizeException) { - $msg = $this->l10n->t('Bigger than maximum allowed size'); - } else if ($ex instanceof TimeoutException) { - $msg = $this->l10n->t('Request timed out'); - } else if ($ex instanceof UnauthorizedException) { - $msg = $this->l10n->t('Required credentials for feed were ' . - 'either missing or incorrect'); - } else if ($ex instanceof ForbiddenException) { - $msg = $this->l10n->t('Forbidden to access feed'); - } + } catch(Exception $ex){ + $this->handleError($ex); + } + + } + - throw new FetcherException($msg); + private function handleError(Exception $ex) { + $msg = $ex->getMessage(); + + if ($ex instanceof MalFormedXmlException) { + $msg = $this->l10n->t('Feed contains invalid XML'); + } else if ($ex instanceof SubscriptionNotFoundException) { + $msg = $this->l10n->t('Feed not found: either the website ' . + 'does not provide a feed or blocks access. To rule out ' . + 'blocking, try to download the feed on your server\'s ' . + 'command line using curl: curl http://the-feed.tld'); + } else if ($ex instanceof UnsupportedFeedFormatException) { + $msg = $this->l10n->t('Detected feed format is not supported'); + } else if ($ex instanceof InvalidCertificateException) { + $msg = $this->l10n->t('SSL Certificate is invalid'); + } else if ($ex instanceof InvalidUrlException) { + $msg = $this->l10n->t('Website not found'); + } else if ($ex instanceof MaxRedirectException) { + $msg = $this->l10n->t('More redirects than allowed, aborting'); + } else if ($ex instanceof MaxSizeException) { + $msg = $this->l10n->t('Bigger than maximum allowed size'); + } else if ($ex instanceof TimeoutException) { + $msg = $this->l10n->t('Request timed out'); + } else if ($ex instanceof UnauthorizedException) { + $msg = $this->l10n->t('Required credentials for feed were ' . + 'either missing or incorrect'); + } else if ($ex instanceof ForbiddenException) { + $msg = $this->l10n->t('Forbidden to access feed'); } + throw new FetcherException($msg); } -- cgit v1.2.3