Skip to content

Commit 5bafd17

Browse files
committed
Throw a specific exception instead of throwing Throwable
1 parent b61c59d commit 5bafd17

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

src/Client.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use SharkMachine\Psr18Shark\Exception\ClientException;
1616
use SharkMachine\Psr18Shark\Exception\CurlException;
1717
use SharkMachine\Psr18Shark\Exception\NoResponseException;
18+
use SharkMachine\Psr18Shark\Exception\SendRequestException;
1819
use SharkMachine\Psr18Shark\Handler\RequestMutationHandlerCollection;
1920
use SharkMachine\Psr18Shark\Handler\ResponseMutationHandlerCollection;
2021
use SharkMachine\Psr18Shark\Handler\TransferHandlerCollection;
@@ -60,7 +61,6 @@ public function __construct(
6061
* @return ResponseInterface
6162
*
6263
* @throws ClientExceptionInterface
63-
* @throws Throwable
6464
*/
6565
public function sendRequest(RequestInterface $request): ResponseInterface
6666
{
@@ -81,7 +81,7 @@ public function sendRequest(RequestInterface $request): ResponseInterface
8181
$handler->handleException($ex);
8282
}
8383
} else {
84-
throw $ex;
84+
throw new SendRequestException($ex);
8585
}
8686
}
8787
if (!isset($response)) {
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace SharkMachine\Psr18Shark\Exception;
6+
7+
use Exception;
8+
use Psr\Http\Client\ClientExceptionInterface;
9+
use Throwable;
10+
11+
final class SendRequestException extends Exception implements ClientExceptionInterface
12+
{
13+
/**
14+
* @param Throwable $previous
15+
*/
16+
public function __construct(Throwable $previous)
17+
{
18+
parent::__construct('Problem with sending request: ' . $previous->getPrevious(), 0, $previous);
19+
}
20+
}

0 commit comments

Comments
 (0)