BadRequestException.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. /**
  3. * SPDX-FileCopyrightText: 2018 Nextcloud GmbH and Nextcloud contributors
  4. * SPDX-License-Identifier: AGPL-3.0-or-later
  5. */
  6. namespace OCP\Federation\Exceptions;
  7. use OCP\HintException;
  8. /**
  9. * Class BadRequestException
  10. *
  11. *
  12. * @since 14.0.0
  13. */
  14. class BadRequestException extends HintException {
  15. /**
  16. * @var string[] $parameterList
  17. */
  18. private $parameterList;
  19. /**
  20. * BadRequestException constructor.
  21. *
  22. * @since 14.0.0
  23. *
  24. * @param array $missingParameters
  25. */
  26. public function __construct(array $missingParameters) {
  27. $l = \OCP\Util::getL10N('federation');
  28. $this->parameterList = $missingParameters;
  29. $parameterList = implode(',', $missingParameters);
  30. $message = 'Parameters missing in order to complete the request. Missing Parameters: ' . $parameterList;
  31. $hint = $l->t('Parameters missing in order to complete the request. Missing Parameters: "%s"', [$parameterList]);
  32. parent::__construct($message, $hint);
  33. }
  34. /**
  35. * get array with the return message as defined in the OCM API
  36. *
  37. * @since 14.0.0
  38. *
  39. * @return array{message: string, validationErrors: array{message: string, name: string}[]}
  40. */
  41. public function getReturnMessage() {
  42. $result = [
  43. 'message' => 'RESOURCE_NOT_FOUND',
  44. 'validationErrors' => [
  45. ]
  46. ];
  47. foreach ($this->parameterList as $missingParameter) {
  48. $result['validationErrors'][] = [
  49. 'name' => $missingParameter,
  50. 'message' => 'NOT_FOUND'
  51. ];
  52. }
  53. return $result;
  54. }
  55. }