GraphQlInputException.php 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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 Magento\Framework\Exception\InputException;
  9. use Magento\Framework\Phrase;
  10. /**
  11. * Exception for GraphQL to be thrown when user supplies invalid input
  12. */
  13. class GraphQlInputException extends InputException implements \GraphQL\Error\ClientAware
  14. {
  15. const EXCEPTION_CATEGORY = 'graphql-input';
  16. /**
  17. * @var boolean
  18. */
  19. private $isSafe;
  20. /**
  21. * Initialize object
  22. *
  23. * @param Phrase $phrase
  24. * @param \Exception $cause
  25. * @param int $code
  26. * @param boolean $isSafe
  27. */
  28. public function __construct(Phrase $phrase, \Exception $cause = null, $code = 0, $isSafe = true)
  29. {
  30. $this->isSafe = $isSafe;
  31. parent::__construct($phrase, $cause, $code);
  32. }
  33. /**
  34. * @inheritdoc
  35. */
  36. public function isClientSafe() : bool
  37. {
  38. return $this->isSafe;
  39. }
  40. /**
  41. * @inheritdoc
  42. */
  43. public function getCategory() : string
  44. {
  45. return self::EXCEPTION_CATEGORY;
  46. }
  47. }