Skip to content

Commit 49cce57

Browse files
authored
Merge pull request #26 from notfoundsam/fixes/api-fix
Fix PageNotfoundException
2 parents 1e9a36e + 9198584 commit 49cce57

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

src/Browser.php

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use GuzzleHttp\Client;
66
use GuzzleHttp\Cookie\CookieJar;
7+
use GuzzleHttp\Exception\ClientException;
78
use SimpleXMLElement;
89
use Yahooauc\Exceptions\ApiException;
910
use Yahooauc\Exceptions\PageNotfoundException;
@@ -493,14 +494,17 @@ private function getBody($url, $options = [], $method = 'GET')
493494
{
494495
if ($this->debug) return $this->readFile($url, $options, $method);
495496

496-
if ($method === 'GET') {
497-
$response = $this->client->get($url, ['query' => $options]);
498-
} else if ($method === 'POST') {
499-
$response = $this->client->post($url, ['form_params' => $options]);
497+
try {
498+
if ($method === 'GET') {
499+
$response = $this->client->get($url, ['query' => $options]);
500+
} else if ($method === 'POST') {
501+
$response = $this->client->post($url, ['form_params' => $options]);
502+
}
500503
}
501-
502-
if ($response->getStatusCode() == 404) {
503-
throw new PageNotfoundException;
504+
catch (ClientException $e) {
505+
if ($e->getCode() == 404) {
506+
throw new PageNotfoundException;
507+
}
504508
}
505509

506510
return $response->getBody()->getContents();

0 commit comments

Comments
 (0)