Add a dedicated exception for participants

Signed-off-by: Joas Schilling <coding@schilljs.com>
This commit is contained in:
Joas Schilling 2017-09-22 14:31:34 +02:00
Родитель 14b9e85dac
Коммит 0c3fdb72b3
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: E166FD8976B3BAC8
4 изменённых файлов: 51 добавлений и 22 удалений

Просмотреть файл

@ -25,6 +25,7 @@
namespace OCA\Spreed\Controller;
use OCA\Spreed\Exceptions\ParticipantNotFoundException;
use OCA\Spreed\Exceptions\RoomNotFoundException;
use OCA\Spreed\Manager;
use OCA\Spreed\Participant;
@ -158,7 +159,7 @@ class RoomController extends OCSController {
try {
$participant = $room->getParticipant($this->userId);
$participantType = $participant->getParticipantType();
} catch (\RuntimeException $e) {
} catch (ParticipantNotFoundException $e) {
$participantType = Participant::GUEST;
}
@ -369,7 +370,7 @@ class RoomController extends OCSController {
$participant = $room->getParticipant($this->userId);
} catch (RoomNotFoundException $e) {
return new DataResponse([], Http::STATUS_NOT_FOUND);
} catch (\RuntimeException $e) {
} catch (ParticipantNotFoundException $e) {
return new DataResponse([], Http::STATUS_NOT_FOUND);
}
@ -399,7 +400,7 @@ class RoomController extends OCSController {
$participant = $room->getParticipant($this->userId);
} catch (RoomNotFoundException $e) {
return new DataResponse([], Http::STATUS_NOT_FOUND);
} catch (\RuntimeException $e) {
} catch (ParticipantNotFoundException $e) {
return new DataResponse([], Http::STATUS_NOT_FOUND);
}
@ -464,7 +465,7 @@ class RoomController extends OCSController {
$participant = $room->getParticipant($this->userId);
} catch (RoomNotFoundException $e) {
return new DataResponse([], Http::STATUS_NOT_FOUND);
} catch (\RuntimeException $e) {
} catch (ParticipantNotFoundException $e) {
return new DataResponse([], Http::STATUS_NOT_FOUND);
}
@ -512,7 +513,7 @@ class RoomController extends OCSController {
$currentParticipant = $room->getParticipant($this->userId);
} catch (RoomNotFoundException $e) {
return new DataResponse([], Http::STATUS_NOT_FOUND);
} catch (\RuntimeException $e) {
} catch (ParticipantNotFoundException $e) {
return new DataResponse([], Http::STATUS_NOT_FOUND);
}
@ -527,7 +528,7 @@ class RoomController extends OCSController {
try {
$targetParticipant = $room->getParticipant($participant);
} catch (\RuntimeException $e) {
} catch (ParticipantNotFoundException $e) {
return new DataResponse([], Http::STATUS_NOT_FOUND);
}
@ -552,7 +553,7 @@ class RoomController extends OCSController {
$room->getParticipant($this->userId); // Check if the participant is part of the room
} catch (RoomNotFoundException $e) {
return new DataResponse([], Http::STATUS_NOT_FOUND);
} catch (\RuntimeException $e) {
} catch (ParticipantNotFoundException $e) {
return new DataResponse([], Http::STATUS_NOT_FOUND);
}
@ -579,7 +580,7 @@ class RoomController extends OCSController {
$currentParticipant = $room->getParticipant($this->userId);
} catch (RoomNotFoundException $e) {
return new DataResponse([], Http::STATUS_NOT_FOUND);
} catch (\RuntimeException $e) {
} catch (ParticipantNotFoundException $e) {
return new DataResponse([], Http::STATUS_NOT_FOUND);
}
@ -589,7 +590,7 @@ class RoomController extends OCSController {
try {
$targetParticipant = $room->getParticipantBySession($participant);
} catch (\RuntimeException $e) {
} catch (ParticipantNotFoundException $e) {
return new DataResponse([], Http::STATUS_NOT_FOUND);
}
@ -613,7 +614,7 @@ class RoomController extends OCSController {
$participant = $room->getParticipant($this->userId);
} catch (RoomNotFoundException $e) {
return new DataResponse([], Http::STATUS_NOT_FOUND);
} catch (\RuntimeException $e) {
} catch (ParticipantNotFoundException $e) {
return new DataResponse([], Http::STATUS_NOT_FOUND);
}
@ -640,7 +641,7 @@ class RoomController extends OCSController {
$participant = $room->getParticipant($this->userId);
} catch (RoomNotFoundException $e) {
return new DataResponse([], Http::STATUS_NOT_FOUND);
} catch (\RuntimeException $e) {
} catch (ParticipantNotFoundException $e) {
return new DataResponse([], Http::STATUS_NOT_FOUND);
}
@ -668,7 +669,7 @@ class RoomController extends OCSController {
$currentParticipant = $room->getParticipant($this->userId);
} catch (RoomNotFoundException $e) {
return new DataResponse([], Http::STATUS_NOT_FOUND);
} catch (\RuntimeException $e) {
} catch (ParticipantNotFoundException $e) {
return new DataResponse([], Http::STATUS_NOT_FOUND);
}
@ -678,7 +679,7 @@ class RoomController extends OCSController {
try {
$targetParticipant = $room->getParticipant($participant);
} catch (\RuntimeException $e) {
} catch (ParticipantNotFoundException $e) {
return new DataResponse([], Http::STATUS_NOT_FOUND);
}
@ -704,7 +705,7 @@ class RoomController extends OCSController {
$currentParticipant = $room->getParticipant($this->userId);
} catch (RoomNotFoundException $e) {
return new DataResponse([], Http::STATUS_NOT_FOUND);
} catch (\RuntimeException $e) {
} catch (ParticipantNotFoundException $e) {
return new DataResponse([], Http::STATUS_NOT_FOUND);
}
@ -718,7 +719,7 @@ class RoomController extends OCSController {
try {
$targetParticipant = $room->getParticipant($participant);
} catch (\RuntimeException $e) {
} catch (ParticipantNotFoundException $e) {
return new DataResponse([], Http::STATUS_NOT_FOUND);
}

Просмотреть файл

@ -0,0 +1,27 @@
<?php
/**
* @copyright Copyright (c) 2017 Joas Schilling <coding@schilljs.com>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
namespace OCA\Spreed\Exceptions;
class ParticipantNotFoundException extends \OutOfBoundsException {
}

Просмотреть файл

@ -22,6 +22,6 @@
namespace OCA\Spreed\Exceptions;
class RoomNotFoundException extends \Exception {
class RoomNotFoundException extends \OutOfBoundsException {
}

Просмотреть файл

@ -25,6 +25,7 @@
namespace OCA\Spreed;
use OCA\Spreed\Exceptions\ParticipantNotFoundException;
use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\IDBConnection;
use OCP\IUser;
@ -119,11 +120,11 @@ class Room {
/**
* @param string $userId
* @return Participant
* @throws \RuntimeException When the user is not a participant
* @throws ParticipantNotFoundException When the user is not a participant
*/
public function getParticipant($userId) {
if (!is_string($userId) || $userId === '') {
throw new \RuntimeException('Not a user');
throw new ParticipantNotFoundException('Not a user');
}
if ($this->currentUser === $userId && $this->participant instanceof Participant) {
@ -140,7 +141,7 @@ class Room {
$result->closeCursor();
if ($row === false) {
throw new \RuntimeException('User is not a participant');
throw new ParticipantNotFoundException('User is not a participant');
}
if ($this->currentUser === $userId) {
@ -154,11 +155,11 @@ class Room {
/**
* @param string $sessionId
* @return Participant
* @throws \RuntimeException When the user is not a participant
* @throws ParticipantNotFoundException When the user is not a participant
*/
public function getParticipantBySession($sessionId) {
if (!is_string($sessionId) || $sessionId === '') {
throw new \RuntimeException('Not a user');
throw new ParticipantNotFoundException('Not a user');
}
$query = $this->db->getQueryBuilder();
@ -171,7 +172,7 @@ class Room {
$result->closeCursor();
if ($row === false) {
throw new \RuntimeException('User is not a participant');
throw new ParticipantNotFoundException('User is not a participant');
}
return new Participant($this->db, $this, $row['userId'], (int) $row['participantType'], (int) $row['lastPing'], $row['sessionId']);