Skip to content

Commit

Permalink
Merge pull request #26 from notfoundsam/fixes/api-fix
Browse files Browse the repository at this point in the history
Fix PageNotfoundException
  • Loading branch information
notfoundsam authored Aug 29, 2021
2 parents 1e9a36e + 9198584 commit 49cce57
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions src/Browser.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 49cce57

Please sign in to comment.