Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/spreed.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVitor Mattos <vitor@php.rio>2022-02-10 16:24:10 +0300
committerVitor Mattos <vitor@php.rio>2022-02-15 18:49:54 +0300
commit0a62079b1754e587138b5732a5e92838859fcde0 (patch)
tree1ee82efee170a35c68ecfe003d051c8be77c4787
parent1a8f3f41cd9a421235ff7181835489a52c65992b (diff)
Make the status code more specific
Signed-off-by: Vitor Mattos <vitor@php.rio>
-rw-r--r--docs/reaction.md5
-rw-r--r--lib/Chat/ReactionManager.php14
-rw-r--r--lib/Controller/ReactionController.php8
-rw-r--r--lib/Exceptions/ReactionNotSupportedException.php29
-rw-r--r--lib/Exceptions/ReactionOutOfContextException.php29
5 files changed, 78 insertions, 7 deletions
diff --git a/docs/reaction.md b/docs/reaction.md
index 183aae338..5fc16e9f6 100644
--- a/docs/reaction.md
+++ b/docs/reaction.md
@@ -17,7 +17,7 @@ Base endpoint is: `/ocs/v2.php/apps/spreed/api/v1`
- Status code:
+ `200 OK` Reaction already exists
+ `201 Created`
- + `400 Bad Request` In case of any other error
+ + `400 Bad Request` In case of no reaction support, message out of reactions context or any other error
+ `404 Not Found` When the conversation or message to react could not be found for the participant
+ `409 Conflict` User already did this reaction to this message
@@ -35,7 +35,7 @@ Base endpoint is: `/ocs/v2.php/apps/spreed/api/v1`
* Response:
- Status code:
+ `201 Created`
- + `400 Bad Request` In case of any other error
+ + `400 Bad Request` In case of no reaction support, message out of reactions context or any other error
+ `404 Not Found` When the conversation or message to react or reaction could not be found for the participant
## Retrieve reactions of a message by type
@@ -52,6 +52,7 @@ Base endpoint is: `/ocs/v2.php/apps/spreed/api/v1`
* Response:
- Status code:
+ `200 OK`
+ + `400 Bad Request` In case of no reaction support, message out of reactions context or any other error
+ `404 Not Found` When the conversation or message to react could not be found for the participant
- Data:
diff --git a/lib/Chat/ReactionManager.php b/lib/Chat/ReactionManager.php
index 9c3b0ea78..98f705213 100644
--- a/lib/Chat/ReactionManager.php
+++ b/lib/Chat/ReactionManager.php
@@ -26,6 +26,8 @@ declare(strict_types=1);
namespace OCA\Talk\Chat;
use OCA\Talk\Exceptions\ReactionAlreadyExistsException;
+use OCA\Talk\Exceptions\ReactionNotSupportedException;
+use OCA\Talk\Exceptions\ReactionOutOfContextException;
use OCA\Talk\Participant;
use OCA\Talk\Room;
use OCP\AppFramework\Utility\ITimeFactory;
@@ -128,16 +130,24 @@ class ReactionManager {
return $reactions;
}
+ /**
+ * @param Room $chat
+ * @param string $messageId
+ * @return IComment
+ * @throws NotFoundException
+ * @throws ReactionNotSupportedException
+ * @throws ReactionOutOfContextException
+ */
public function getCommentToReact(Room $chat, string $messageId): IComment {
if (!$this->commentsManager->supportReactions()) {
- throw new NotFoundException('Reactions unsupported');
+ throw new ReactionNotSupportedException();
}
$comment = $this->commentsManager->get($messageId);
if ($comment->getObjectType() !== 'chat'
|| $comment->getObjectId() !== (string) $chat->getId()
|| $comment->getVerb() !== 'comment') {
- throw new NotFoundException('Message not found in the right context');
+ throw new ReactionOutOfContextException();
}
return $comment;
diff --git a/lib/Controller/ReactionController.php b/lib/Controller/ReactionController.php
index ca0de0331..a16820ade 100644
--- a/lib/Controller/ReactionController.php
+++ b/lib/Controller/ReactionController.php
@@ -27,6 +27,8 @@ namespace OCA\Talk\Controller;
use OCA\Talk\Chat\ReactionManager;
use OCA\Talk\Exceptions\ReactionAlreadyExistsException;
+use OCA\Talk\Exceptions\ReactionNotSupportedException;
+use OCA\Talk\Exceptions\ReactionOutOfContextException;
use OCP\AppFramework\Http;
use OCP\AppFramework\Http\DataResponse;
use OCP\Comments\NotFoundException;
@@ -63,7 +65,7 @@ class ReactionController extends AEnvironmentAwareController {
return new DataResponse([], Http::STATUS_NOT_FOUND);
} catch (ReactionAlreadyExistsException $e) {
return new DataResponse([], Http::STATUS_OK);
- } catch (\Exception $e) {
+ } catch (ReactionNotSupportedException | ReactionOutOfContextException | \Exception $e) {
return new DataResponse([], Http::STATUS_BAD_REQUEST);
}
return new DataResponse([], Http::STATUS_CREATED);
@@ -84,7 +86,7 @@ class ReactionController extends AEnvironmentAwareController {
try {
// Verify that messageId is part of the room
$this->reactionManager->getCommentToReact($this->getRoom(), (string) $messageId);
- } catch (NotFoundException $e) {
+ } catch (ReactionNotSupportedException | ReactionOutOfContextException | NotFoundException $e) {
return new DataResponse([], Http::STATUS_NOT_FOUND);
}
@@ -117,7 +119,7 @@ class ReactionController extends AEnvironmentAwareController {
try {
// Verify that messageId is part of the room
$this->reactionManager->getCommentToReact($this->getRoom(), (string) $messageId);
- } catch (NotFoundException $e) {
+ } catch (ReactionNotSupportedException | ReactionOutOfContextException | NotFoundException $e) {
return new DataResponse([], Http::STATUS_NOT_FOUND);
}
diff --git a/lib/Exceptions/ReactionNotSupportedException.php b/lib/Exceptions/ReactionNotSupportedException.php
new file mode 100644
index 000000000..478f6a80a
--- /dev/null
+++ b/lib/Exceptions/ReactionNotSupportedException.php
@@ -0,0 +1,29 @@
+<?php
+
+declare(strict_types=1);
+/**
+ * @copyright Copyright (c) 2022, Vitor Mattos <vitor@php.rio>
+ *
+ * @author Vitor Mattos <vitor@php.rio>
+ *
+ * @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\Talk\Exceptions;
+
+class ReactionNotSupportedException extends \Exception {
+}
diff --git a/lib/Exceptions/ReactionOutOfContextException.php b/lib/Exceptions/ReactionOutOfContextException.php
new file mode 100644
index 000000000..499dee69b
--- /dev/null
+++ b/lib/Exceptions/ReactionOutOfContextException.php
@@ -0,0 +1,29 @@
+<?php
+
+declare(strict_types=1);
+/**
+ * @copyright Copyright (c) 2022, Vitor Mattos <vitor@php.rio>
+ *
+ * @author Vitor Mattos <vitor@php.rio>
+ *
+ * @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\Talk\Exceptions;
+
+class ReactionOutOfContextException extends \Exception {
+}