Improved poll error handling
This commit is contained in:
parent
d3f85ad779
commit
437591b297
@ -491,8 +491,13 @@ class APnutI
|
||||
public function getPollFromToken(int $poll_id, ?string $poll_token = null): Poll
|
||||
{
|
||||
$poll_token_query = empty($poll_token) ? '' : '?poll_token=' . $poll_token;
|
||||
try {
|
||||
$res = $this->get('/polls/' . $poll_id . $poll_token_query);
|
||||
return $this->getPollFromResponse($res);
|
||||
} catch (NotAuthorizedException $nauth) {
|
||||
$this->logger->error('Not authorized when fetching poll');
|
||||
throw new PollAccessRestrictedException();
|
||||
}
|
||||
}
|
||||
|
||||
public function getPoll(int $poll_id, ?string $poll_token = null): Poll
|
||||
@ -513,8 +518,13 @@ class APnutI
|
||||
'include_html' => false,
|
||||
'include_post_raw' => true
|
||||
];
|
||||
try {
|
||||
$res = $this->get('/posts/' . $post_id, $args);
|
||||
return $this->getPollFromResponse($res);
|
||||
} catch (NotAuthorizedException $nauth) {
|
||||
$this->logger->error('Not authorized when fetching poll');
|
||||
throw new PollAccessRestrictedException();
|
||||
}
|
||||
} else {
|
||||
$this->logger->debug('Poll token seems to be an actual poll token');
|
||||
return $this->getPollFromToken($poll_id, $poll_token);
|
||||
|
Loading…
Reference in New Issue
Block a user