Skip to content

Commit 4029f1b

Browse files
authored
Merge pull request #27 from bechir/handle_exception
Handle exception of network errors
2 parents 2515e28 + dddcaea commit 4029f1b

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

lib/Cleantalk.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -444,10 +444,7 @@ private function httpRequest($msg) {
444444

445445
return false;
446446

447-
} else {
448-
449-
$servers = $this->get_servers_ip($url_host);
450-
447+
} else if(null !== $servers = $this->get_servers_ip($url_host)) {
451448
// Loop until find work server
452449
foreach ($servers as $server) {
453450

@@ -461,6 +458,8 @@ private function httpRequest($msg) {
461458
break;
462459
}
463460
}
461+
} else {
462+
throw TransportException::fromUrlHostError($url_host);
464463
}
465464
}
466465

lib/TransportException.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
namespace Cleantalk;
4+
5+
use Exception;
6+
7+
class TransportException extends Exception
8+
{
9+
/**
10+
* @param string $url
11+
* @return self
12+
*/
13+
public static function fromUrlHostError($url_host)
14+
{
15+
return new self("Couldn't resolve host name for \"$url_host\".\nCheck your network connectivity.");
16+
}
17+
}

0 commit comments

Comments
 (0)