diff options
author | provokateurin <kate@provokateurin.de> | 2024-10-22 08:20:04 +0200 |
---|---|---|
committer | provokateurin <kate@provokateurin.de> | 2024-10-28 09:07:41 +0100 |
commit | aacb3ddc1eb4342ce13d193e650c4fb5d223dd0e (patch) | |
tree | 0868f4cda8d7cb1a4c864bcb4df3f00488a25551 | |
parent | e6c11e1be09a13b13df0371b2cff56656c93d4da (diff) | |
download | nextcloud-server-aacb3ddc1eb4342ce13d193e650c4fb5d223dd0e.tar.gz nextcloud-server-aacb3ddc1eb4342ce13d193e650c4fb5d223dd0e.zip |
fix(files_sharing): Cleanup error messagesfix/files_sharing/cleanup-error-messages
Signed-off-by: provokateurin <kate@provokateurin.de>
-rw-r--r-- | apps/files_sharing/lib/Controller/ShareAPIController.php | 18 | ||||
-rw-r--r-- | apps/files_sharing/tests/ApiTest.php | 2 | ||||
-rw-r--r-- | apps/files_sharing/tests/Controller/ShareAPIControllerTest.php | 2 |
3 files changed, 11 insertions, 11 deletions
diff --git a/apps/files_sharing/lib/Controller/ShareAPIController.php b/apps/files_sharing/lib/Controller/ShareAPIController.php index d6800acf655..077eb4b35a3 100644 --- a/apps/files_sharing/lib/Controller/ShareAPIController.php +++ b/apps/files_sharing/lib/Controller/ShareAPIController.php @@ -646,7 +646,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. @@ -812,12 +812,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); @@ -1349,11 +1348,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 { @@ -1362,7 +1361,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)); @@ -1449,7 +1449,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(); @@ -2141,9 +2142,8 @@ class ShareAPIController extends OCSController { $provider->sendMailNotification($share); return new 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 ec76186c566..c20644fc2fc 100644 --- a/apps/files_sharing/tests/ApiTest.php +++ b/apps/files_sharing/tests/ApiTest.php @@ -1299,7 +1299,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 aeba8cb9aea..768bebe0271 100644 --- a/apps/files_sharing/tests/Controller/ShareAPIControllerTest.php +++ b/apps/files_sharing/tests/Controller/ShareAPIControllerTest.php @@ -2217,7 +2217,7 @@ class ShareAPIControllerTest extends TestCase { public function testCreateShareInvalidExpireDate(): void { $this->expectException(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(); |