Skip to content

Commit

Permalink
fix(files_sharing): Cleanup error messages
Browse files Browse the repository at this point in the history
Signed-off-by: provokateurin <[email protected]>

[skip ci]
  • Loading branch information
provokateurin authored and backportbot[bot] committed Oct 28, 2024
1 parent 0e4ab29 commit 9fe8574
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
16 changes: 9 additions & 7 deletions apps/files_sharing/lib/Controller/ShareAPIController.php
Original file line number Diff line number Diff line change
Expand Up @@ -645,7 +645,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 @@ -811,12 +811,11 @@ public function createShare(
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);
Expand Down Expand Up @@ -1343,11 +1342,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 @@ -1356,7 +1355,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 @@ -1443,7 +1443,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 Expand Up @@ -2137,6 +2138,7 @@ public function sendShareEmail(string $id, $password = ''): DataResponse {
} catch(OCSBadRequestException $e) {
throw $e;
} catch (Exception $e) {
$this->logger->error($e->getMessage(), ['exception' => $e]);
throw new OCSException($this->l->t('Error while sending mail notification'));
}

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 @@ -1294,7 +1294,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

0 comments on commit 9fe8574

Please sign in to comment.