Skip to content
This repository has been archived by the owner on Mar 1, 2023. It is now read-only.

Commit

Permalink
Handle all Guzzle exceptions and provide a message for them
Browse files Browse the repository at this point in the history
Signed-off-by: Yoshi2889 <rick.2889@gmail.com>
  • Loading branch information
NanoSector committed Jan 3, 2016
1 parent 699d721 commit 3b54383
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
12 changes: 5 additions & 7 deletions src/LinkSniffer.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

namespace WildPHP\Modules\LinkSniffer;

use GuzzleHttp\Exception\ClientException;
use GuzzleHttp\Exception\GuzzleException;
use WildPHP\API\ShortenUri;
use WildPHP\BaseModule;
use WildPHP\CoreModules\Connection\IrcDataObject;
Expand Down Expand Up @@ -64,10 +64,8 @@ public function sniffLinks(IrcDataObject $message)
{
try
{
$content_type = SnifferHelper::getContentTypeFromUri($uri);

$shortUri = $this->createShortUri($uri);

$content_type = SnifferHelper::getContentTypeFromUri($uri);
$title = '(not a web page, content type: ' . $content_type . ')';

if ($content_type == 'text/html')
Expand All @@ -84,10 +82,10 @@ public function sniffLinks(IrcDataObject $message)
return;
}

// ClientExceptions can be thrown by Guzzle. If one occurs, just give up.
catch (ClientException $e)
// Guzzle exceptions (such as connection timeouts) should be ignored.
catch (GuzzleException $e)
{
return;
$title = '(link was unresponsive: ' . $uri . ')';
}

if (!empty($title) && !empty($shortUri))
Expand Down
4 changes: 2 additions & 2 deletions tests/CacheTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ public function testAddEntry()
$uriCache = new UriCache();

$uriCache->addCacheItem('googleUri', 'Google');

$checkObject = new CacheItem();
$checkObject->setTitle('Google');
$checkObject->setExpireTime(time() + 60 * 60);

$retrieved = $uriCache->getCacheItem('googleUri');

$this->assertEquals($checkObject, $retrieved);
$this->assertSame($checkObject, $retrieved);
}

public function testRemoveItem()
Expand Down

0 comments on commit 3b54383

Please sign in to comment.