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();