GraphQlAuthenticationException.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. declare(strict_types=1);
  7. namespace Magento\Framework\GraphQl\Exception;
  8. use GraphQL\Error\ClientAware;
  9. use Magento\Framework\Exception\AuthenticationException;
  10. use Magento\Framework\Phrase;
  11. /**
  12. * Exception for GraphQL to be thrown when authentication fails
  13. */
  14. class GraphQlAuthenticationException extends AuthenticationException implements ClientAware
  15. {
  16. /**
  17. * Describing a category of the error
  18. */
  19. const EXCEPTION_CATEGORY = 'graphql-authentication';
  20. /**
  21. * @var boolean
  22. */
  23. private $isSafe;
  24. /**
  25. * @param Phrase $phrase
  26. * @param \Exception $cause
  27. * @param int $code
  28. * @param boolean $isSafe
  29. */
  30. public function __construct(Phrase $phrase, \Exception $cause = null, $code = 0, $isSafe = true)
  31. {
  32. $this->isSafe = $isSafe;
  33. parent::__construct($phrase, $cause, $code);
  34. }
  35. /**
  36. * @inheritdoc
  37. */
  38. public function isClientSafe(): bool
  39. {
  40. return $this->isSafe;
  41. }
  42. /**
  43. * @inheritdoc
  44. */
  45. public function getCategory(): string
  46. {
  47. return self::EXCEPTION_CATEGORY;
  48. }
  49. }