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

Commit 3b54383

Browse files
committed
Handle all Guzzle exceptions and provide a message for them
Signed-off-by: Yoshi2889 <rick.2889@gmail.com>
1 parent 699d721 commit 3b54383

File tree

2 files changed

+7
-9
lines changed

2 files changed

+7
-9
lines changed

src/LinkSniffer.php

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
namespace WildPHP\Modules\LinkSniffer;
2222

23-
use GuzzleHttp\Exception\ClientException;
23+
use GuzzleHttp\Exception\GuzzleException;
2424
use WildPHP\API\ShortenUri;
2525
use WildPHP\BaseModule;
2626
use WildPHP\CoreModules\Connection\IrcDataObject;
@@ -64,10 +64,8 @@ public function sniffLinks(IrcDataObject $message)
6464
{
6565
try
6666
{
67-
$content_type = SnifferHelper::getContentTypeFromUri($uri);
68-
6967
$shortUri = $this->createShortUri($uri);
70-
68+
$content_type = SnifferHelper::getContentTypeFromUri($uri);
7169
$title = '(not a web page, content type: ' . $content_type . ')';
7270

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

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

9391
if (!empty($title) && !empty($shortUri))

tests/CacheTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,13 @@ public function testAddEntry()
3131
$uriCache = new UriCache();
3232

3333
$uriCache->addCacheItem('googleUri', 'Google');
34+
3435
$checkObject = new CacheItem();
3536
$checkObject->setTitle('Google');
36-
$checkObject->setExpireTime(time() + 60 * 60);
3737

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

40-
$this->assertEquals($checkObject, $retrieved);
40+
$this->assertSame($checkObject, $retrieved);
4141
}
4242

4343
public function testRemoveItem()

0 commit comments

Comments
 (0)