ApiAuthorizationException.php 784 B

12345678910111213141516171819202122232425262728293031323334
  1. <?php
  2. namespace Shaarli\Api\Exceptions;
  3. /**
  4. * Class ApiAuthorizationException
  5. *
  6. * Request not authorized, return a 401 HTTP code.
  7. */
  8. class ApiAuthorizationException extends ApiException
  9. {
  10. /**
  11. * {@inheritdoc}
  12. */
  13. public function getApiResponse()
  14. {
  15. $this->setMessage('Not authorized');
  16. return $this->buildApiResponse(401);
  17. }
  18. /**
  19. * Set the exception message.
  20. *
  21. * We only return a generic error message in production mode to avoid giving
  22. * to much security information.
  23. *
  24. * @param $message string the exception message.
  25. */
  26. public function setMessage($message)
  27. {
  28. $original = $this->debug === true ? ': '. $this->getMessage() : '';
  29. $this->message = $message . $original;
  30. }
  31. }