diff --git a/app/Helper/Curl.php b/app/Helper/Curl.php index 309cac1..43d97ca 100644 --- a/app/Helper/Curl.php +++ b/app/Helper/Curl.php @@ -4,6 +4,7 @@ declare(strict_types=1); namespace App\Helper; +use App\Exception\BusinessException; use GuzzleHttp\Client; use Hyperf\Guzzle\HandlerStackFactory; @@ -35,7 +36,6 @@ class Curl * @param string $url * @param array $headers * @return array - * @throws \GuzzleHttp\Exception\GuzzleException */ public static function get(string $url, array $headers = []) : array { @@ -46,7 +46,11 @@ class Curl $options['headers'] = $headers; } - $response = $client->get($url, $options); + try { + $response = $client->get($url, $options); + } catch (\Throwable $throwable) { + throw new BusinessException($throwable->getCode(), $throwable->getMessage()); + } if ($response->getStatusCode() === 200) { return json_decode($response->getBody()->getContents(), true); @@ -62,7 +66,6 @@ class Curl * @param array $data * @param array $headers * @return array - * @throws \GuzzleHttp\Exception\GuzzleException */ public static function post(string $url, array $data = [], array $headers = []) : array { @@ -73,7 +76,11 @@ class Curl $options['headers'] = $headers; } - $response = $client->post($url, $options); + try { + $response = $client->post($url, $options); + } catch (\Throwable $throwable) { + throw new BusinessException($throwable->getCode(), $throwable->getMessage()); + } if ($response->getStatusCode() === 200) { return json_decode($response->getBody()->getContents(), true);