Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[stable28] fix(files_sharing): Cleanup error messages #48935

Merged
merged 1 commit into from
Oct 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions apps/files_sharing/lib/Controller/ShareAPIController.php
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ protected function formatShare(IShare $share, Node $recipientNode = null): array
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.
Expand Down Expand Up @@ -675,7 +675,7 @@ public function createShare(
$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.
Expand Down Expand Up @@ -826,12 +826,11 @@ public function createShare(
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);
Expand Down Expand Up @@ -1352,11 +1351,11 @@ public function updateShare(
$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 {
Expand All @@ -1365,7 +1364,8 @@ public function updateShare(
$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));
Expand Down Expand Up @@ -1456,7 +1456,8 @@ public function acceptShare(string $id): DataResponse {
$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();
Expand Down
2 changes: 1 addition & 1 deletion apps/files_sharing/tests/ApiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1317,7 +1317,7 @@ public function testPublicLinkExpireDate($date, $valid) {
$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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2208,7 +2208,7 @@ public function testCreateShareValidExpireDate() {

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();

Expand Down
Loading