From 919858423315bb07266a6bfb2b565fd4a3ee318d Mon Sep 17 00:00:00 2001 From: notfoundsam Date: Sun, 29 Aug 2021 22:26:39 +0900 Subject: [PATCH] Fix PageNotfoundException --- src/Browser.php | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/Browser.php b/src/Browser.php index db673e0..8369d63 100644 --- a/src/Browser.php +++ b/src/Browser.php @@ -4,6 +4,7 @@ use GuzzleHttp\Client; use GuzzleHttp\Cookie\CookieJar; +use GuzzleHttp\Exception\ClientException; use SimpleXMLElement; use Yahooauc\Exceptions\ApiException; use Yahooauc\Exceptions\PageNotfoundException; @@ -493,14 +494,17 @@ private function getBody($url, $options = [], $method = 'GET') { if ($this->debug) return $this->readFile($url, $options, $method); - if ($method === 'GET') { - $response = $this->client->get($url, ['query' => $options]); - } else if ($method === 'POST') { - $response = $this->client->post($url, ['form_params' => $options]); + try { + if ($method === 'GET') { + $response = $this->client->get($url, ['query' => $options]); + } else if ($method === 'POST') { + $response = $this->client->post($url, ['form_params' => $options]); + } } - - if ($response->getStatusCode() == 404) { - throw new PageNotfoundException; + catch (ClientException $e) { + if ($e->getCode() == 404) { + throw new PageNotfoundException; + } } return $response->getBody()->getContents();