aboutsummaryrefslogtreecommitdiffstats
path: root/apps/files_sharing
diff options
context:
space:
mode:
authorprovokateurin <kate@provokateurin.de>2024-10-22 08:20:04 +0200
committerprovokateurin <kate@provokateurin.de>2024-10-28 13:26:16 +0100
commit35d22348208321d0dd6f56e035ddb91fc4653c16 (patch)
tree870de4284c608d466049f0b84e561b55f82cadef /apps/files_sharing
parent70d9e4a229f638c37c7c721efcb222d90568311b (diff)
downloadnextcloud-server-35d22348208321d0dd6f56e035ddb91fc4653c16.tar.gz
nextcloud-server-35d22348208321d0dd6f56e035ddb91fc4653c16.zip
fix(files_sharing): Cleanup error messagesbackport/48918/stable28
Signed-off-by: provokateurin <kate@provokateurin.de>
Diffstat (limited to 'apps/files_sharing')
-rw-r--r--apps/files_sharing/lib/Controller/ShareAPIController.php19
-rw-r--r--apps/files_sharing/tests/ApiTest.php2
-rw-r--r--apps/files_sharing/tests/Controller/ShareAPIControllerTest.php2
3 files changed, 12 insertions, 11 deletions
diff --git a/apps/files_sharing/lib/Controller/ShareAPIController.php b/apps/files_sharing/lib/Controller/ShareAPIController.php
index 266c1f9474c..7de1376b951 100644
--- a/apps/files_sharing/lib/Controller/ShareAPIController.php
+++ b/apps/files_sharing/lib/Controller/ShareAPIController.php
@@ -190,7 +190,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.
@@ -675,7 +675,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.
@@ -826,12 +826,11 @@ class ShareAPIController extends OCSController {
try {
$share = $this->shareManager->createShare($share);
} catch (GenericShareException $e) {
- \OC::$server->getLogger()->logException($e);
$code = $e->getCode() === 0 ? 403 : $e->getCode();
throw new OCSException($e->getHint(), $code);
} catch (\Exception $e) {
- \OC::$server->getLogger()->logException($e);
- throw new OCSForbiddenException($e->getMessage(), $e);
+ $this->logger->error($e->getMessage(), ['exception' => $e]);
+ throw new OCSForbiddenException('Failed to create share.', $e);
}
$output = $this->formatShare($share);
@@ -1352,11 +1351,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 {
@@ -1365,7 +1364,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));
@@ -1456,7 +1456,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 1c7937ea01f..62aaf14f82e 100644
--- a/apps/files_sharing/tests/Controller/ShareAPIControllerTest.php
+++ b/apps/files_sharing/tests/Controller/ShareAPIControllerTest.php
@@ -2208,7 +2208,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();