Skip to content

Commit

Permalink
Merge pull request #27 from bechir/handle_exception
Browse files Browse the repository at this point in the history
Handle exception of network errors
  • Loading branch information
Glomberg authored Jan 21, 2021
2 parents 2515e28 + dddcaea commit 4029f1b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
7 changes: 3 additions & 4 deletions lib/Cleantalk.php
Original file line number Diff line number Diff line change
Expand Up @@ -444,10 +444,7 @@ private function httpRequest($msg) {

return false;

} else {

$servers = $this->get_servers_ip($url_host);

} else if(null !== $servers = $this->get_servers_ip($url_host)) {
// Loop until find work server
foreach ($servers as $server) {

Expand All @@ -461,6 +458,8 @@ private function httpRequest($msg) {
break;
}
}
} else {
throw TransportException::fromUrlHostError($url_host);
}
}

Expand Down
17 changes: 17 additions & 0 deletions lib/TransportException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

namespace Cleantalk;

use Exception;

class TransportException extends Exception
{
/**
* @param string $url
* @return self
*/
public static function fromUrlHostError($url_host)
{
return new self("Couldn't resolve host name for \"$url_host\".\nCheck your network connectivity.");
}
}

0 comments on commit 4029f1b

Please sign in to comment.