Skip to content

Commit

Permalink
fixed bug
Browse files Browse the repository at this point in the history
  • Loading branch information
chaz6chez committed Apr 7, 2024
1 parent 7ae61a4 commit d1b4841
Showing 1 changed file with 12 additions and 13 deletions.
25 changes: 12 additions & 13 deletions src/ApiClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
namespace Workbunny\WebmanPushServer;

use GuzzleHttp\Exception\GuzzleException;
use GuzzleHttp\Exception\RequestException;
use GuzzleHttp\RequestOptions;
use Workbunny\WebmanPushServer\Events\Subscribe;
use GuzzleHttp\Client;
Expand Down Expand Up @@ -98,21 +99,19 @@ public function request(string $method, string $path, string $body, array $query
'Connection' => $this->settings['keep-alive'] ? 'keep-alive' : 'close',
'X-Push-Client' => 'push-server ' . VERSION
] + $headers,
RequestOptions::HTTP_ERRORS => false,
RequestOptions::HTTP_ERRORS => true,
]);
$status = $response->getStatusCode();
$body = $response->getBody()->getContents();
if (
$status === 200 or
($status >= 400 and $status < 500)
) {
return @json_decode($body, true) ?: [];
}
} catch (GuzzleException $e) {
$body = $e->getMessage();
$status = $e->getCode();
return json_decode($response->getBody()->getContents(), true) ?: [];
} catch (RequestException $e) {
throw new ClientException(
$e->getResponse()?->getBody()->getContents() ?: $e->getMessage(),
$e->getResponse()?->getStatusCode() ?: 0
);
} catch (\Throwable $throwable) {
throw new ClientException(
"Push client request failed. [{$throwable->getMessage()}]", $throwable->getCode(), $throwable
);
}
throw new ClientException($body, $status);
}

/**
Expand Down

0 comments on commit d1b4841

Please sign in to comment.