InvalidPath.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. /**
  3. * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
  4. * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
  5. * SPDX-License-Identifier: AGPL-3.0-only
  6. */
  7. namespace OCA\DAV\Connector\Sabre\Exception;
  8. use Sabre\DAV\Exception;
  9. class InvalidPath extends Exception {
  10. public const NS_OWNCLOUD = 'http://owncloud.org/ns';
  11. /**
  12. * @param string $message
  13. * @param bool $retry
  14. * @param \Exception|null $previous
  15. */
  16. public function __construct(
  17. $message,
  18. private $retry = false,
  19. ?\Exception $previous = null,
  20. ) {
  21. parent::__construct($message, 0, $previous);
  22. }
  23. /**
  24. * Returns the HTTP status code for this exception
  25. *
  26. * @return int
  27. */
  28. public function getHTTPCode() {
  29. return 400;
  30. }
  31. /**
  32. * This method allows the exception to include additional information
  33. * into the WebDAV error response
  34. *
  35. * @param \Sabre\DAV\Server $server
  36. * @param \DOMElement $errorNode
  37. * @return void
  38. */
  39. public function serialize(\Sabre\DAV\Server $server, \DOMElement $errorNode) {
  40. // set ownCloud namespace
  41. $errorNode->setAttribute('xmlns:o', self::NS_OWNCLOUD);
  42. // adding the retry node
  43. $error = $errorNode->ownerDocument->createElementNS('o:', 'o:retry', var_export($this->retry, true));
  44. $errorNode->appendChild($error);
  45. // adding the message node
  46. $error = $errorNode->ownerDocument->createElementNS('o:', 'o:reason', $this->getMessage());
  47. $errorNode->appendChild($error);
  48. }
  49. }