diff options
author | Bernhard Posselt <dev@bernhard-posselt.com> | 2016-03-26 20:18:19 +0100 |
---|---|---|
committer | Bernhard Posselt <dev@bernhard-posselt.com> | 2016-03-26 20:18:19 +0100 |
commit | b35e703294615456334fc37cb325ffa9d191276b (patch) | |
tree | 12c89115d973e041ec9e8ae64abb2fb19037392c | |
parent | 3d95832ec6902b2dd1991ca5403d5956013f5e26 (diff) |
split up exception handling into a separate method
-rw-r--r-- | fetcher/feedfetcher.php | 65 |
1 files 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); } |