aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorprovokateurin <kate@provokateurin.de>2024-10-22 08:20:04 +0200
committerprovokateurin <kate@provokateurin.de>2024-10-28 13:11:47 +0100
commite4603a7e270316b458490773a4a8e795626eba67 (patch)
tree13e0e830a4e9e292123798050d81b519a8d98b83
parent94a623aec7d4877eea08d0e9970cfc8d85c073c2 (diff)
downloadnextcloud-server-backport/48918/stable29.tar.gz
nextcloud-server-backport/48918/stable29.zip
fix(files_sharing): Cleanup error messagesbackport/48918/stable29
Signed-off-by: provokateurin <kate@provokateurin.de>
-rw-r--r--apps/files_sharing/lib/Controller/ShareAPIController.php17
-rw-r--r--apps/files_sharing/tests/ApiTest.php2
-rw-r--r--apps/files_sharing/tests/Controller/ShareAPIControllerTest.php2
3 files changed, 11 insertions, 10 deletions
diff --git a/apps/files_sharing/lib/Controller/ShareAPIController.php b/apps/files_sharing/lib/Controller/ShareAPIController.php
index 50889c13ce3..bfc462ec901 100644
--- a/apps/files_sharing/lib/Controller/ShareAPIController.php
+++ b/apps/files_sharing/lib/Controller/ShareAPIController.php
@@ -188,7 +188,7 @@ class ShareAPIController extends OCSController {
if ($isOwnShare) {
$result['item_permissions'] = $node->getPermissions();
}
-
+
// If we're on the recipient side, the node permissions
// are bound to the share permissions. So we need to
// adjust the permissions to the share permissions if necessary.
@@ -674,7 +674,7 @@ class ShareAPIController extends OCSController {
$expireDateTime = $this->parseDate($expireDate);
$share->setExpirationDate($expireDateTime);
} catch (\Exception $e) {
- throw new OCSNotFoundException($this->l->t('Invalid date, date format must be YYYY-MM-DD'));
+ throw new OCSNotFoundException($e->getMessage(), $e);
}
} else {
// Client sent empty string for expire date.
@@ -825,12 +825,11 @@ class ShareAPIController extends OCSController {
try {
$share = $this->shareManager->createShare($share);
} catch (GenericShareException $e) {
- $this->logger->error($e->getMessage(), ['exception' => $e]);
$code = $e->getCode() === 0 ? 403 : $e->getCode();
throw new OCSException($e->getHint(), $code);
} catch (\Exception $e) {
$this->logger->error($e->getMessage(), ['exception' => $e]);
- throw new OCSForbiddenException($e->getMessage(), $e);
+ throw new OCSForbiddenException('Failed to create share.', $e);
}
$output = $this->formatShare($share);
@@ -1350,11 +1349,11 @@ class ShareAPIController extends OCSController {
$share->setExpirationDate(null);
} elseif ($expireDate !== null) {
try {
- $expireDate = $this->parseDate($expireDate);
+ $expireDateTime = $this->parseDate($expireDate);
+ $share->setExpirationDate($expireDateTime);
} catch (\Exception $e) {
throw new OCSBadRequestException($e->getMessage(), $e);
}
- $share->setExpirationDate($expireDate);
}
try {
@@ -1363,7 +1362,8 @@ class ShareAPIController extends OCSController {
$code = $e->getCode() === 0 ? 403 : $e->getCode();
throw new OCSException($e->getHint(), (int)$code);
} catch (\Exception $e) {
- throw new OCSBadRequestException($e->getMessage(), $e);
+ $this->logger->error($e->getMessage(), ['exception' => $e]);
+ throw new OCSBadRequestException('Failed to update share.', $e);
}
return new DataResponse($this->formatShare($share));
@@ -1452,7 +1452,8 @@ class ShareAPIController extends OCSController {
$code = $e->getCode() === 0 ? 403 : $e->getCode();
throw new OCSException($e->getHint(), (int)$code);
} catch (\Exception $e) {
- throw new OCSBadRequestException($e->getMessage(), $e);
+ $this->logger->error($e->getMessage(), ['exception' => $e]);
+ throw new OCSBadRequestException('Failed to accept share.', $e);
}
return new DataResponse();
diff --git a/apps/files_sharing/tests/ApiTest.php b/apps/files_sharing/tests/ApiTest.php
index cdb6d2ddcca..1dc52d9f586 100644
--- a/apps/files_sharing/tests/ApiTest.php
+++ b/apps/files_sharing/tests/ApiTest.php
@@ -1317,7 +1317,7 @@ class ApiTest extends TestCase {
$this->assertTrue($valid);
} catch (OCSNotFoundException $e) {
$this->assertFalse($valid);
- $this->assertEquals('Invalid date, date format must be YYYY-MM-DD', $e->getMessage());
+ $this->assertEquals('Invalid date. Format must be YYYY-MM-DD', $e->getMessage());
$ocs->cleanup();
return;
}
diff --git a/apps/files_sharing/tests/Controller/ShareAPIControllerTest.php b/apps/files_sharing/tests/Controller/ShareAPIControllerTest.php
index 61bfee21da2..f909cf97538 100644
--- a/apps/files_sharing/tests/Controller/ShareAPIControllerTest.php
+++ b/apps/files_sharing/tests/Controller/ShareAPIControllerTest.php
@@ -2223,7 +2223,7 @@ class ShareAPIControllerTest extends TestCase {
public function testCreateShareInvalidExpireDate() {
$this->expectException(\OCP\AppFramework\OCS\OCSNotFoundException::class);
- $this->expectExceptionMessage('Invalid date, date format must be YYYY-MM-DD');
+ $this->expectExceptionMessage('Invalid date. Format must be YYYY-MM-DD');
$ocs = $this->mockFormatShare();