diff --git a/.gitignore b/.gitignore index 6250ba4..40b7d35 100644 --- a/.gitignore +++ b/.gitignore @@ -1,8 +1,8 @@ -.DS_Store/ +.DS_Store .idea/ .vscode/ vendor/ -composer.lock \ No newline at end of file +composer.lock diff --git a/composer.json b/composer.json index 67d4b9c..8425df4 100644 --- a/composer.json +++ b/composer.json @@ -16,8 +16,8 @@ ], "require": { "php": ">=8.0.0", - "react/http": "^1.6.0", - "clue/socks-react": "^1.3.0", + "react/http": "^1.8.0", + "clue/socks-react": "^1.4.0", "react/promise-timer": "^1.9.0" }, "require-dev": { diff --git a/src/AsyncRequest.php b/src/AsyncRequest.php index eb1b55c..ad783ab 100644 --- a/src/AsyncRequest.php +++ b/src/AsyncRequest.php @@ -129,14 +129,29 @@ private function request(string $url, array $params = [], array $headers = [], s // Added Request Timeout return timeout($req, $this->timeout)->then( - function (ResponseInterface $response) use ($canResponseDecode) { + function ($response) use ($canResponseDecode) { + if($response instanceof ResponseInterface){ + return [ + 'result' => true, + 'code' => $response->getStatusCode(), + 'headers' => $response->getHeaders(), + 'body' => $canResponseDecode + ? json_decode($response->getBody()->getContents(), true) + : $response->getBody()->getContents() + ]; + } + + if($response instanceof ResponseException){ + return [ + 'result' => false, + 'code' => $response->getCode(), + 'body' => $response->getTraceAsString() + ]; + } + return [ - 'result' => true, - 'code' => $response->getStatusCode(), - 'headers' => $response->getHeaders(), - 'body' => $canResponseDecode - ? json_decode($response->getBody()->getContents(), true) - : $response->getBody()->getContents() + 'result' => false, + 'code' => 100_000, ]; }, function ($error) use ($canResponseDecode) { @@ -159,4 +174,4 @@ function ($error) use ($canResponseDecode) { } ); } -} \ No newline at end of file +}