From 144caadd3fa86fd905fc0a692930005fa6b9c1b2 Mon Sep 17 00:00:00 2001 From: fantasticbin Date: Mon, 14 Nov 2022 14:17:01 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=84=E8=AF=B7=E6=B1=82=E5=A4=84?= =?UTF-8?q?=E7=90=86=E5=85=AC=E5=85=B1=E7=B1=BB=E7=9A=84=E5=BC=82=E5=B8=B8?= =?UTF-8?q?=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Helper/Curl.php | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) 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);