diff --git a/apps/files_sharing/lib/Controller/ShareAPIController.php b/apps/files_sharing/lib/Controller/ShareAPIController.php index 616c175a9b41a..f6c106b9b0800 100644 --- a/apps/files_sharing/lib/Controller/ShareAPIController.php +++ b/apps/files_sharing/lib/Controller/ShareAPIController.php @@ -34,6 +34,7 @@ use OCP\Files\IRootFolder; use OCP\Files\Node; use OCP\Files\NotFoundException; +use OCP\HintException; use OCP\IConfig; use OCP\IDateTimeZone; use OCP\IGroupManager; @@ -46,7 +47,6 @@ use OCP\Lock\LockedException; use OCP\Mail\IMailer; use OCP\Server; -use OCP\Share\Exceptions\GenericShareException; use OCP\Share\Exceptions\ShareNotFound; use OCP\Share\IManager; use OCP\Share\IProviderFactory; @@ -810,7 +810,7 @@ public function createShare( try { $share = $this->shareManager->createShare($share); - } catch (GenericShareException $e) { + } catch (HintException $e) { $code = $e->getCode() === 0 ? 403 : $e->getCode(); throw new OCSException($e->getHint(), $code); } catch (\Exception $e) { @@ -1351,7 +1351,7 @@ public function updateShare( try { $share = $this->shareManager->updateShare($share); - } catch (GenericShareException $e) { + } catch (HintException $e) { $code = $e->getCode() === 0 ? 403 : $e->getCode(); throw new OCSException($e->getHint(), (int)$code); } catch (\Exception $e) { @@ -1439,7 +1439,7 @@ public function acceptShare(string $id): DataResponse { try { $this->shareManager->acceptShare($share, $this->currentUser); - } catch (GenericShareException $e) { + } catch (HintException $e) { $code = $e->getCode() === 0 ? 403 : $e->getCode(); throw new OCSException($e->getHint(), (int)$code); } catch (\Exception $e) { diff --git a/lib/private/Share20/Manager.php b/lib/private/Share20/Manager.php index ce0dbd9b17a0b..2cc11c2c6346d 100644 --- a/lib/private/Share20/Manager.php +++ b/lib/private/Share20/Manager.php @@ -97,7 +97,7 @@ private function splitFullId($id) { * Verify if a password meets all requirements * * @param string $password - * @throws \Exception + * @throws HintException */ protected function verifyPassword($password) { if ($password === null) { @@ -113,7 +113,8 @@ protected function verifyPassword($password) { try { $this->dispatcher->dispatchTyped(new ValidatePasswordPolicyEvent($password)); } catch (HintException $e) { - throw new \Exception($e->getHint()); + /* Wrap in a 400 bad request error */ + throw new HintException($e->getMessage(), $e->getHint(), 400, $e); } } @@ -772,6 +773,7 @@ public function createShare(IShare $share) { * @param IShare $share * @return IShare The share object * @throws \InvalidArgumentException + * @throws HintException */ public function updateShare(IShare $share) { $expirationDateUpdated = false; diff --git a/tests/lib/Share20/ManagerTest.php b/tests/lib/Share20/ManagerTest.php index 15ecc839451a4..c0cf0ca9c129b 100644 --- a/tests/lib/Share20/ManagerTest.php +++ b/tests/lib/Share20/ManagerTest.php @@ -594,7 +594,7 @@ public function testVerifyPasswordHookFails() { $this->assertInstanceOf(ValidatePasswordPolicyEvent::class, $event); /** @var ValidatePasswordPolicyEvent $event */ $this->assertSame('password', $event->getPassword()); - throw new HintException('message', 'password not accepted'); + throw new HintException('password not accepted'); } );