Skip to content

Commit

Permalink
Add explicit exception handling
Browse files Browse the repository at this point in the history
  • Loading branch information
mattamon committed Mar 7, 2024
1 parent 337b5da commit 9b76072
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
1 change: 1 addition & 0 deletions src/Security/Trait/RequestTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ private function getAuthToken(Request $request): string
private function getCurrentRequest(RequestStack $requestStack): Request
{
$request = $requestStack->getCurrentRequest();

if(!$request) {
throw new NoRequestException('No request found');
}
Expand Down
12 changes: 7 additions & 5 deletions src/Security/Voter/PublicTokenVoter.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,18 +49,20 @@ protected function supports(string $attribute, mixed $subject): bool

/**
* @throws NoRequestException
* @throws NoAuthTokenFound
* @throws NonPublicTranslationException
*/
protected function voteOnAttribute(string $attribute, mixed $subject, TokenInterface $token): bool
{

$request = $this->getCurrentRequest($this->requestStack);

$authToken = $this->getAuthToken($request);

if ($this->securityService->checkAuthToken($authToken)) {
return true;
try {
$authToken = $this->getAuthToken($request);
if ($this->securityService->checkAuthToken($authToken)) {
return true;
}
} catch (NoAuthTokenFound) {
return $this->voteOnRequest($request, $subject);
}

return $this->voteOnRequest($request, $subject);
Expand Down

0 comments on commit 9b76072

Please sign in to comment.