From 9fe85746873b2d7512489f62010c11441831212c Mon Sep 17 00:00:00 2001 From: provokateurin Date: Tue, 22 Oct 2024 08:20:04 +0200 Subject: [PATCH] fix(files_sharing): Cleanup error messages Signed-off-by: provokateurin [skip ci] --- .../lib/Controller/ShareAPIController.php | 16 +++++++++------- apps/files_sharing/tests/ApiTest.php | 2 +- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/apps/files_sharing/lib/Controller/ShareAPIController.php b/apps/files_sharing/lib/Controller/ShareAPIController.php index dfbcc31ba81d7..215a925286809 100644 --- a/apps/files_sharing/lib/Controller/ShareAPIController.php +++ b/apps/files_sharing/lib/Controller/ShareAPIController.php @@ -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. @@ -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); @@ -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 { @@ -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)); @@ -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(); @@ -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')); } diff --git a/apps/files_sharing/tests/ApiTest.php b/apps/files_sharing/tests/ApiTest.php index 770ebd14f1eec..9884465c97356 100644 --- a/apps/files_sharing/tests/ApiTest.php +++ b/apps/files_sharing/tests/ApiTest.php @@ -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; }