From 13d49b6ebe27df5d6a69e9d5940f92946cc93817 Mon Sep 17 00:00:00 2001 From: Maxence Lange Date: Wed, 28 Nov 2018 14:39:25 -0100 Subject: [PATCH] exception handling Signed-off-by: Maxence Lange --- lib/Controller/ActivityPubController.php | 6 +++-- lib/Controller/NavigationController.php | 6 +++-- lib/Db/ActorsRequest.php | 30 ++++++++++-------------- lib/Service/ActorService.php | 2 +- lib/Service/InstanceService.php | 1 + 5 files changed, 23 insertions(+), 22 deletions(-) diff --git a/lib/Controller/ActivityPubController.php b/lib/Controller/ActivityPubController.php index 119076cc..acd79fa3 100644 --- a/lib/Controller/ActivityPubController.php +++ b/lib/Controller/ActivityPubController.php @@ -125,7 +125,6 @@ class ActivityPubController extends Controller { * @param string $username * * @return Response - * @throws \OC\User\NoUserException */ public function actor(string $username): Response { if (!$this->checkSourceActivityStreams()) { @@ -210,10 +209,13 @@ class ActivityPubController extends Controller { public function inbox(string $username): Response { try { - $actor = $this->actorService->getActor($username); + $this->activityService->checkRequest($this->request); $body = file_get_contents('php://input'); + // TODO - check the recipient <-> username +// $actor = $this->actorService->getActor($username); + $this->miscService->log('Inbox: ' . $body); $activity = $this->importService->import($body); diff --git a/lib/Controller/NavigationController.php b/lib/Controller/NavigationController.php index 864b9eb8..37f7050f 100644 --- a/lib/Controller/NavigationController.php +++ b/lib/Controller/NavigationController.php @@ -125,7 +125,6 @@ class NavigationController extends Controller { * @NoSubAdminRequired * * @return TemplateResponse - * @throws NoUserException */ public function navigate($path = ''): TemplateResponse { $data = [ @@ -162,6 +161,10 @@ class NavigationController extends Controller { $data['serverData']['firstrun'] = true; } catch (AccountAlreadyExistsException $e) { // we do nothing + } catch (NoUserException $e) { + // well, should not happens + } catch (SocialAppConfigException $e) { + // neither. } return new TemplateResponse(Application::APP_NAME, 'main', $data); @@ -231,7 +234,6 @@ class NavigationController extends Controller { * @param $username * * @return RedirectResponse|PublicTemplateResponse - * @throws NoUserException */ public function public($username) { if (\OC::$server->getUserSession() diff --git a/lib/Db/ActorsRequest.php b/lib/Db/ActorsRequest.php index 09b37e4b..00572296 100644 --- a/lib/Db/ActorsRequest.php +++ b/lib/Db/ActorsRequest.php @@ -60,32 +60,28 @@ class ActorsRequest extends ActorsRequestBuilder { * @param Person $actor * * @return string - * @throws \Exception + * @throws SocialAppConfigException */ public function create(Person $actor): string { $id = $this->configService->getUrlSocial() . '@' . $actor->getPreferredUsername(); - try { - $qb = $this->getActorsInsertSql(); + $qb = $this->getActorsInsertSql(); - $qb->setValue('id', $qb->createNamedParameter($id)) + $qb->setValue('id', $qb->createNamedParameter($id)) // ->setValue('type', $qb->createNamedParameter($actor->getType())) - ->setValue('user_id', $qb->createNamedParameter($actor->getUserId())) - ->setValue('name', $qb->createNamedParameter($actor->getName())) - ->setValue('summary', $qb->createNamedParameter($actor->getSummary())) - ->setValue( - 'preferred_username', $qb->createNamedParameter($actor->getPreferredUsername()) - ) - ->setValue('public_key', $qb->createNamedParameter($actor->getPublicKey())) - ->setValue('private_key', $qb->createNamedParameter($actor->getPrivateKey())); + ->setValue('user_id', $qb->createNamedParameter($actor->getUserId())) + ->setValue('name', $qb->createNamedParameter($actor->getName())) + ->setValue('summary', $qb->createNamedParameter($actor->getSummary())) + ->setValue( + 'preferred_username', $qb->createNamedParameter($actor->getPreferredUsername()) + ) + ->setValue('public_key', $qb->createNamedParameter($actor->getPublicKey())) + ->setValue('private_key', $qb->createNamedParameter($actor->getPrivateKey())); - $qb->execute(); + $qb->execute(); - return $id; - } catch (\Exception $e) { - throw $e; - } + return $id; } diff --git a/lib/Service/ActorService.php b/lib/Service/ActorService.php index 348d1a1f..70fb824e 100644 --- a/lib/Service/ActorService.php +++ b/lib/Service/ActorService.php @@ -142,7 +142,7 @@ class ActorService { * * @throws AccountAlreadyExistsException * @throws NoUserException - * @throws Exception + * @throws SocialAppConfigException */ public function createActor(string $userId, string $username) { diff --git a/lib/Service/InstanceService.php b/lib/Service/InstanceService.php index 0d7eefef..911a86c9 100644 --- a/lib/Service/InstanceService.php +++ b/lib/Service/InstanceService.php @@ -80,6 +80,7 @@ class InstanceService { * @return mixed * @throws RequestException * @throws InvalidResourceException + * @throws Request410Exception */ public function retrieveAccount(string $account) { $account = $this->withoutBeginAt($account);