Skip to content

Commit

Permalink
IBX-5094: Added try-catch block for UnauthorizedException (#136)
Browse files Browse the repository at this point in the history
* IBX-5094: Added try-catch block for UnauthorizedException

* Added throw UserError exception for UnauthorizedException
  • Loading branch information
mateuszdebinski authored Aug 4, 2023
1 parent dbdaaae commit d4a9610
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/GraphQL/Resolver/SectionResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@
*/
namespace EzSystems\EzPlatformGraphQL\GraphQL\Resolver;

use eZ\Publish\API\Repository\Exceptions\UnauthorizedException;
use eZ\Publish\API\Repository\Values\Content\Section;
use eZ\Publish\API\Repository\SectionService;
use GraphQL\Error\UserError;

/**
* @internal
Expand All @@ -23,8 +26,12 @@ public function __construct(SectionService $sectionService)
$this->sectionService = $sectionService;
}

public function resolveSectionById($sectionId)
public function resolveSectionById($sectionId): ?Section
{
return $this->sectionService->loadSection($sectionId);
try {
return $this->sectionService->loadSection($sectionId);
} catch (UnauthorizedException $e) {
throw new UserError($e->getMessage());
}
}
}

0 comments on commit d4a9610

Please sign in to comment.