Commit 86b883c1 authored by 谢宇轩's avatar 谢宇轩

fix: 控制异常范围

parent 5d1dd142
...@@ -107,8 +107,6 @@ class Application implements ClientInterface ...@@ -107,8 +107,6 @@ class Application implements ClientInterface
* @param RequestInterface $request * @param RequestInterface $request
* @return ResponseInterface * @return ResponseInterface
* @throws ApplicationException * @throws ApplicationException
* @throws GuzzleException
*
*/ */
public function sendRequest(RequestInterface $request): ResponseInterface public function sendRequest(RequestInterface $request): ResponseInterface
{ {
...@@ -173,7 +171,7 @@ class Application implements ClientInterface ...@@ -173,7 +171,7 @@ class Application implements ClientInterface
$this->logger->error("sdk etrror, bad client!"); $this->logger->error("sdk etrror, bad client!");
} }
if (!($request instanceof SdkRequest)) { if (!($request instanceof SdkRequest)) {
throw $exception; throw new ApplicationException($exception->getMessage(), null, [], $exception);
} }
throw new ApplicationException($exception->getMessage(), $request, [], $exception); throw new ApplicationException($exception->getMessage(), $request, [], $exception);
} }
......
...@@ -13,18 +13,18 @@ class ApplicationException extends ConnectException implements SdkExceptionInter ...@@ -13,18 +13,18 @@ class ApplicationException extends ConnectException implements SdkExceptionInter
/** /**
* @param string $message * @param string $message
* @param SdkRequest $request * @param SdkRequest|null $request
* @param array<string, mixed> $handlerContext * @param array<string, mixed> $handlerContext
* @param Throwable|null $previous * @param Throwable|null $previous
*/ */
public function __construct( public function __construct(
string $message, string $message,
SdkRequest $request, SdkRequest $request = null,
array $handlerContext = [], array $handlerContext = [],
?\Throwable $previous = null, ?\Throwable $previous = null
) { ) {
$this->endpoint = $request->getEndpoint(); $this->endpoint = is_null($request) ? "" : $request->getEndpoint();
$this->action = $request->getAction(); $this->action = is_null($request) ? "" : $request->getAction();
parent::__construct($message, $request, $previous, $handlerContext); parent::__construct($message, $request, $previous, $handlerContext);
} }
} }
\ No newline at end of file
...@@ -6,7 +6,6 @@ declare(strict_types=1); ...@@ -6,7 +6,6 @@ declare(strict_types=1);
namespace Jiwei\{{ Package }}\Endpoint; namespace Jiwei\{{ Package }}\Endpoint;
use Closure; use Closure;
use GuzzleHttp\Exception\GuzzleException;
use Jiwei\EasyHttpSdk\Application; use Jiwei\EasyHttpSdk\Application;
use Jiwei\EasyHttpSdk\Exception\SdkException; use Jiwei\EasyHttpSdk\Exception\SdkException;
use Jiwei\EasyHttpSdk\Exception\ApplicationException; use Jiwei\EasyHttpSdk\Exception\ApplicationException;
...@@ -50,7 +49,6 @@ class {{ Endpoint }} ...@@ -50,7 +49,6 @@ class {{ Endpoint }}
* @throws ApplicationException * @throws ApplicationException
* @throws SdkException * @throws SdkException
* @throws TimeOutExcetpion * @throws TimeOutExcetpion
* @throws GuzzleException
*/ */
public function {{ item.Action }}({{ item.Args }}?Closure $catch = null, ?Closure $then = null) public function {{ item.Action }}({{ item.Args }}?Closure $catch = null, ?Closure $then = null)
{ {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment