LLM OCP API: Use OCP\Common\Exception\NotFoundException

Signed-off-by: Marcel Klehr <mklehr@gmx.net>
This commit is contained in:
Marcel Klehr 2023-06-27 16:51:41 +02:00
parent a7cd6bf5b8
commit b00a9a6eae
3 changed files with 7 additions and 4 deletions

View file

@ -29,6 +29,7 @@ namespace OC\Core\Controller;
use InvalidArgumentException; use InvalidArgumentException;
use OCP\AppFramework\Http; use OCP\AppFramework\Http;
use OCP\AppFramework\Http\DataResponse; use OCP\AppFramework\Http\DataResponse;
use OCP\Common\Exception\NotFoundException;
use OCP\IL10N; use OCP\IL10N;
use OCP\IRequest; use OCP\IRequest;
use OCP\LanguageModel\AbstractLanguageModelTask; use OCP\LanguageModel\AbstractLanguageModelTask;
@ -87,7 +88,7 @@ class LanguageModelApiController extends \OCP\AppFramework\OCSController {
return new DataResponse([ return new DataResponse([
'task' => $task, 'task' => $task,
]); ]);
} catch (\ValueError $e) { } catch (NotFoundException $e) {
return new DataResponse(['message' => $this->l->t('Task not found')], Http::STATUS_NOT_FOUND); return new DataResponse(['message' => $this->l->t('Task not found')], Http::STATUS_NOT_FOUND);
} catch (\RuntimeException $e) { } catch (\RuntimeException $e) {
return new DataResponse(['message' => $this->l->t('Internal error')], Http::STATUS_INTERNAL_SERVER_ERROR); return new DataResponse(['message' => $this->l->t('Internal error')], Http::STATUS_INTERNAL_SERVER_ERROR);

View file

@ -8,6 +8,7 @@ use OC\LanguageModel\Db\TaskMapper;
use OCP\AppFramework\Db\DoesNotExistException; use OCP\AppFramework\Db\DoesNotExistException;
use OCP\AppFramework\Db\MultipleObjectsReturnedException; use OCP\AppFramework\Db\MultipleObjectsReturnedException;
use OCP\BackgroundJob\IJobList; use OCP\BackgroundJob\IJobList;
use OCP\Common\Exception\NotFoundException;
use OCP\DB\Exception; use OCP\DB\Exception;
use OCP\IServerContainer; use OCP\IServerContainer;
use OCP\LanguageModel\AbstractLanguageModelTask; use OCP\LanguageModel\AbstractLanguageModelTask;
@ -152,14 +153,14 @@ class LanguageModelManager implements ILanguageModelManager {
* @param int $id The id of the task * @param int $id The id of the task
* @return ILanguageModelTask * @return ILanguageModelTask
* @throws RuntimeException If the query failed * @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 { public function getTask(int $id): ILanguageModelTask {
try { try {
$taskEntity = $this->taskMapper->find($id); $taskEntity = $this->taskMapper->find($id);
return AbstractLanguageModelTask::fromTaskEntity($taskEntity); return AbstractLanguageModelTask::fromTaskEntity($taskEntity);
} catch (DoesNotExistException $e) { } 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) { } catch (MultipleObjectsReturnedException $e) {
throw new RuntimeException('Could not uniquely identify task with given id'); throw new RuntimeException('Could not uniquely identify task with given id');
} catch (Exception $e) { } catch (Exception $e) {

View file

@ -26,6 +26,7 @@ declare(strict_types=1);
namespace OCP\LanguageModel; namespace OCP\LanguageModel;
use OCP\Common\Exception\NotFoundException;
use OCP\PreConditionNotMetException; use OCP\PreConditionNotMetException;
use RuntimeException; use RuntimeException;
@ -70,7 +71,7 @@ interface ILanguageModelManager {
* @param int $id The id of the task * @param int $id The id of the task
* @return ILanguageModelTask * @return ILanguageModelTask
* @throws RuntimeException If the query failed * @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 * @since 28.0.0
*/ */
public function getTask(int $id): ILanguageModelTask; public function getTask(int $id): ILanguageModelTask;