1
0

StorageNotAvailableException.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. // use OCP namespace for all classes that are considered public.
  8. // This means that they should be used by apps instead of the internal Nextcloud classes
  9. namespace OCP\Files;
  10. use OCP\HintException;
  11. /**
  12. * Storage is temporarily not available
  13. * @since 6.0.0
  14. * @since 8.2.1 based on HintException
  15. */
  16. class StorageNotAvailableException extends HintException {
  17. /**
  18. * @since 8.2.0
  19. */
  20. public const STATUS_SUCCESS = 0;
  21. /**
  22. * @since 8.2.0
  23. */
  24. public const STATUS_ERROR = 1;
  25. /**
  26. * @since 8.2.0
  27. */
  28. public const STATUS_INDETERMINATE = 2;
  29. /**
  30. * @since 8.2.0
  31. */
  32. public const STATUS_INCOMPLETE_CONF = 3;
  33. /**
  34. * @since 8.2.0
  35. */
  36. public const STATUS_UNAUTHORIZED = 4;
  37. /**
  38. * @since 8.2.0
  39. */
  40. public const STATUS_TIMEOUT = 5;
  41. /**
  42. * @since 8.2.0
  43. */
  44. public const STATUS_NETWORK_ERROR = 6;
  45. /**
  46. * StorageNotAvailableException constructor.
  47. *
  48. * @param string $message
  49. * @param int $code
  50. * @param \Exception|null $previous
  51. * @since 6.0.0
  52. */
  53. public function __construct($message = '', $code = self::STATUS_ERROR, ?\Exception $previous = null) {
  54. $l = \OCP\Util::getL10N('core');
  55. parent::__construct($message, $l->t('Storage is temporarily not available'), $code, $previous);
  56. }
  57. /**
  58. * Get the name for a status code
  59. *
  60. * @param int $code
  61. * @return string
  62. * @since 9.0.0
  63. */
  64. public static function getStateCodeName($code) {
  65. switch ($code) {
  66. case self::STATUS_SUCCESS:
  67. return 'ok';
  68. case self::STATUS_ERROR:
  69. return 'error';
  70. case self::STATUS_INDETERMINATE:
  71. return 'indeterminate';
  72. case self::STATUS_UNAUTHORIZED:
  73. return 'unauthorized';
  74. case self::STATUS_TIMEOUT:
  75. return 'timeout';
  76. case self::STATUS_NETWORK_ERROR:
  77. return 'network error';
  78. default:
  79. return 'unknown';
  80. }
  81. }
  82. }