TooManyRequests.php 927 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors
  5. * SPDX-License-Identifier: AGPL-3.0-or-later
  6. */
  7. namespace OCA\DAV\Connector\Sabre\Exception;
  8. use DOMElement;
  9. use Sabre\DAV\Exception\NotAuthenticated;
  10. use Sabre\DAV\Server;
  11. class TooManyRequests extends NotAuthenticated {
  12. public const NS_OWNCLOUD = 'http://owncloud.org/ns';
  13. public function getHTTPCode() {
  14. return 429;
  15. }
  16. /**
  17. * This method allows the exception to include additional information
  18. * into the WebDAV error response
  19. *
  20. * @param Server $server
  21. * @param DOMElement $errorNode
  22. * @return void
  23. */
  24. public function serialize(Server $server, DOMElement $errorNode) {
  25. // set ownCloud namespace
  26. $errorNode->setAttribute('xmlns:o', self::NS_OWNCLOUD);
  27. $error = $errorNode->ownerDocument->createElementNS('o:', 'o:hint', 'too many requests');
  28. $errorNode->appendChild($error);
  29. }
  30. }