From 688721b1670ac8c2cf520539c9777c9b8d889305 Mon Sep 17 00:00:00 2001 From: aymm Date: Thu, 11 Mar 2021 05:57:37 +0000 Subject: [PATCH] Added HttpPnutForbiddenException --- src/APnutI.php | 8 ++++++-- src/Exceptions/HttpPnutForbiddenException.php | 8 ++++++++ src/Meta.php | 4 ++++ 3 files changed, 18 insertions(+), 2 deletions(-) create mode 100644 src/Exceptions/HttpPnutForbiddenException.php diff --git a/src/APnutI.php b/src/APnutI.php index 4e7c07a..d022219 100644 --- a/src/APnutI.php +++ b/src/APnutI.php @@ -11,6 +11,7 @@ use APnutI\Exceptions\NotAuthorizedException; use APnutI\Exceptions\HttpPnutException; use APnutI\Exceptions\HttpPnutRedirectException; use APnutI\Exceptions\NotSupportedPollException; +use APnutI\Exceptions\HttpPnutForbiddenException; use APnutI\Meta; use Monolog\Logger; use Monolog\Handler\RotatingFileHandler; @@ -239,7 +240,7 @@ class APnutI $response_headers_string = print_r($this->headers, true); $request_headers_string = print_r($headers, true); $parameters_string = print_r($parameters, true); - $this->logger->error("Error, no authorized: {$pe->getMessage()}"); + $this->logger->error("Error: {$pe->getMessage()}"); $this->logger->error("Method: {$method}"); $this->logger->error("Parameters: {$parameters_string}"); $this->logger->error("Request headers: {$request_headers_string}"); @@ -459,12 +460,15 @@ class APnutI public function getPoll(int $poll_id): Poll { - $res = $this->get('/polls/' . $poll_id); try { + $res = $this->get('/polls/' . $poll_id); return new Poll($res); } catch (NotSupportedPollException $e) { $this->logger->error('Poll not supported: '.json_encode($res)); throw $e; + } catch (HttpPnutForbiddenException $fe) { + $this->logger->error('Poll token required and not provided!: '.json_encode($res)); + throw $fe; } } diff --git a/src/Exceptions/HttpPnutForbiddenException.php b/src/Exceptions/HttpPnutForbiddenException.php new file mode 100644 index 0000000..ca285c1 --- /dev/null +++ b/src/Exceptions/HttpPnutForbiddenException.php @@ -0,0 +1,8 @@ +code === 401) { throw new NotAuthorizedException($meta['error_message']); } + if ($this->code === 403) { + throw new HttpPnutForbiddenException(); + } if ($this->code === 404) { throw new NotFoundException(); }