AuthenticationException.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. namespace Webkul\BagistoApi\Exception;
  3. use ApiPlatform\Metadata\Exception\HttpExceptionInterface;
  4. use ApiPlatform\Metadata\Exception\ProblemExceptionInterface;
  5. /**
  6. * Thrown when a request lacks credentials. Maps to HTTP 401 in REST.
  7. */
  8. class AuthenticationException extends \Exception implements \GraphQL\Error\ClientAware, HttpExceptionInterface, ProblemExceptionInterface, \GraphQL\Error\ProvidesExtensions
  9. {
  10. private int $status = 401;
  11. private array $headers = [];
  12. public function isClientSafe(): bool
  13. {
  14. return true;
  15. }
  16. public function getExtensions(): array
  17. {
  18. return [
  19. 'code' => 'UNAUTHENTICATED',
  20. 'category' => $this->getCategory(),
  21. 'status' => $this->getStatus()
  22. ];
  23. }
  24. public function getCategory(): string
  25. {
  26. return 'authentication';
  27. }
  28. public function getStatusCode(): int
  29. {
  30. return $this->status;
  31. }
  32. public function getHeaders(): array
  33. {
  34. return $this->headers;
  35. }
  36. public function getType(): string
  37. {
  38. return '/errors/401';
  39. }
  40. public function getTitle(): ?string
  41. {
  42. return 'Unauthorized';
  43. }
  44. public function getStatus(): ?int
  45. {
  46. return $this->status;
  47. }
  48. public function getDetail(): ?string
  49. {
  50. return $this->message;
  51. }
  52. public function getInstance(): ?string
  53. {
  54. return null;
  55. }
  56. }