Skip to content

Commit

Permalink
validate callable retry logic in Host
Browse files Browse the repository at this point in the history
  • Loading branch information
truongbo17 committed Dec 24, 2022
1 parent 19bddd0 commit a0b8dec
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Exception/InvalidCallableException.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

final class InvalidCallableException extends Exception
{
public function __construct(string $message = 'Callable must return a boolean value', int $code = 0, ?\Throwable $previous = null)
public function __construct(string $message = 'Invalid callable retry logic', int $code = 0, ?\Throwable $previous = null)
{
parent::__construct($message, $code, $previous);
}
Expand Down
6 changes: 6 additions & 0 deletions src/Servers/Host.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace TruongBo\ProxyRotation\Servers;

use TruongBo\ProxyRotation\Exception\HostException;
use TruongBo\ProxyRotation\Exception\InvalidCallableException;

final class Host implements HostInterface
{
Expand Down Expand Up @@ -62,9 +63,14 @@ public function validateConstructor()
/**
* Add retry logic
* @param callable $retry_logic
* @throws InvalidCallableException
*/
public function addRetryLogic(callable $retry_logic): void
{
if(!is_callable($retry_logic)){
throw new InvalidCallableException();
}

$this->retries_logic[] = $retry_logic;
}

Expand Down

0 comments on commit a0b8dec

Please sign in to comment.