Added HttpPnutForbiddenException

This commit is contained in:
aymm 2021-03-11 05:57:37 +00:00
parent 45fe5f4156
commit 688721b167
3 changed files with 18 additions and 2 deletions

View File

@ -11,6 +11,7 @@ use APnutI\Exceptions\NotAuthorizedException;
use APnutI\Exceptions\HttpPnutException; use APnutI\Exceptions\HttpPnutException;
use APnutI\Exceptions\HttpPnutRedirectException; use APnutI\Exceptions\HttpPnutRedirectException;
use APnutI\Exceptions\NotSupportedPollException; use APnutI\Exceptions\NotSupportedPollException;
use APnutI\Exceptions\HttpPnutForbiddenException;
use APnutI\Meta; use APnutI\Meta;
use Monolog\Logger; use Monolog\Logger;
use Monolog\Handler\RotatingFileHandler; use Monolog\Handler\RotatingFileHandler;
@ -239,7 +240,7 @@ class APnutI
$response_headers_string = print_r($this->headers, true); $response_headers_string = print_r($this->headers, true);
$request_headers_string = print_r($headers, true); $request_headers_string = print_r($headers, true);
$parameters_string = print_r($parameters, 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("Method: {$method}");
$this->logger->error("Parameters: {$parameters_string}"); $this->logger->error("Parameters: {$parameters_string}");
$this->logger->error("Request headers: {$request_headers_string}"); $this->logger->error("Request headers: {$request_headers_string}");
@ -459,12 +460,15 @@ class APnutI
public function getPoll(int $poll_id): Poll public function getPoll(int $poll_id): Poll
{ {
$res = $this->get('/polls/' . $poll_id);
try { try {
$res = $this->get('/polls/' . $poll_id);
return new Poll($res); return new Poll($res);
} catch (NotSupportedPollException $e) { } catch (NotSupportedPollException $e) {
$this->logger->error('Poll not supported: '.json_encode($res)); $this->logger->error('Poll not supported: '.json_encode($res));
throw $e; throw $e;
} catch (HttpPnutForbiddenException $fe) {
$this->logger->error('Poll token required and not provided!: '.json_encode($res));
throw $fe;
} }
} }

View File

@ -0,0 +1,8 @@
<?php
namespace APnutI\Exceptions;
use APnutI\Exceptions\HttpPnutException;
class HttpPnutForbiddenException extends HttpPnutException
{
}

View File

@ -5,6 +5,7 @@ namespace APnutI;
use APnutI\Exceptions\PnutException; use APnutI\Exceptions\PnutException;
use APnutI\Exceptions\NotAuthorizedException; use APnutI\Exceptions\NotAuthorizedException;
use APnutI\Exceptions\NotFoundException; use APnutI\Exceptions\NotFoundException;
use APnutI\Exceptions\HttpPnutForbiddenException;
class Meta class Meta
{ {
@ -35,6 +36,9 @@ class Meta
}if ($this->code === 401) { }if ($this->code === 401) {
throw new NotAuthorizedException($meta['error_message']); throw new NotAuthorizedException($meta['error_message']);
} }
if ($this->code === 403) {
throw new HttpPnutForbiddenException();
}
if ($this->code === 404) { if ($this->code === 404) {
throw new NotFoundException(); throw new NotFoundException();
} }