]> source.dussan.org Git - nextcloud-server.git/commitdiff
LLM OCP API: Use OCP\Common\Exception\NotFoundException
authorMarcel Klehr <mklehr@gmx.net>
Tue, 27 Jun 2023 14:51:41 +0000 (16:51 +0200)
committerMarcel Klehr <mklehr@gmx.net>
Wed, 9 Aug 2023 08:01:02 +0000 (10:01 +0200)
Signed-off-by: Marcel Klehr <mklehr@gmx.net>
(cherry picked from commit b00a9a6eaeeafce11e0141199f37d8a105050cce)

core/Controller/LanguageModelApiController.php
lib/private/LanguageModel/LanguageModelManager.php
lib/public/LanguageModel/ILanguageModelManager.php

index 5699dd7552673bf49ed5d3dcc2fe6a7cd394f5b8..a4f83cc1b1151d6a45c7f3904accadb0dd0aa823 100644 (file)
@@ -29,6 +29,7 @@ namespace OC\Core\Controller;
 use InvalidArgumentException;
 use OCP\AppFramework\Http;
 use OCP\AppFramework\Http\DataResponse;
+use OCP\Common\Exception\NotFoundException;
 use OCP\IL10N;
 use OCP\IRequest;
 use OCP\LanguageModel\AbstractLanguageModelTask;
@@ -87,7 +88,7 @@ class LanguageModelApiController extends \OCP\AppFramework\OCSController {
                        return new DataResponse([
                                'task' => $task,
                        ]);
-               } catch (\ValueError $e) {
+               } catch (NotFoundException $e) {
                        return new DataResponse(['message' => $this->l->t('Task not found')], Http::STATUS_NOT_FOUND);
                } catch (\RuntimeException $e) {
                        return new DataResponse(['message' => $this->l->t('Internal error')], Http::STATUS_INTERNAL_SERVER_ERROR);
index 340116e7d719c60792515552146b82ba46bbfddc..4a29e8d8b18c6b83a2be618316e7d0236e499424 100644 (file)
@@ -8,6 +8,7 @@ use OC\LanguageModel\Db\TaskMapper;
 use OCP\AppFramework\Db\DoesNotExistException;
 use OCP\AppFramework\Db\MultipleObjectsReturnedException;
 use OCP\BackgroundJob\IJobList;
+use OCP\Common\Exception\NotFoundException;
 use OCP\DB\Exception;
 use OCP\IServerContainer;
 use OCP\LanguageModel\AbstractLanguageModelTask;
@@ -152,14 +153,14 @@ class LanguageModelManager implements ILanguageModelManager {
         * @param int $id The id of the task
         * @return ILanguageModelTask
         * @throws RuntimeException If the query failed
-        * @throws \ValueError If the task could not be found
+        * @throws NotFoundException If the task could not be found
         */
        public function getTask(int $id): ILanguageModelTask {
                try {
                        $taskEntity = $this->taskMapper->find($id);
                        return AbstractLanguageModelTask::fromTaskEntity($taskEntity);
                } catch (DoesNotExistException $e) {
-                       throw new \ValueError('Could not find task with the provided id');
+                       throw new NotFoundException('Could not find task with the provided id');
                } catch (MultipleObjectsReturnedException $e) {
                        throw new RuntimeException('Could not uniquely identify task with given id');
                } catch (Exception $e) {
index 80546149a6206166c44ecaab22e5ac6e172f5943..4c28ca86d725790def945fec216d878dca18e160 100644 (file)
@@ -26,6 +26,7 @@ declare(strict_types=1);
 
 namespace OCP\LanguageModel;
 
+use OCP\Common\Exception\NotFoundException;
 use OCP\PreConditionNotMetException;
 use RuntimeException;
 
@@ -70,7 +71,7 @@ interface ILanguageModelManager {
         * @param int $id The id of the task
         * @return ILanguageModelTask
         * @throws RuntimeException If the query failed
-        * @throws \ValueError If the task could not be found
+        * @throws NotFoundException If the task could not be found
         * @since 28.0.0
         */
        public function getTask(int $id): ILanguageModelTask;