diff --git a/core/Controller/TextToImageApiController.php b/core/Controller/TextToImageApiController.php index 27833c0035d..45443347ee0 100644 --- a/core/Controller/TextToImageApiController.php +++ b/core/Controller/TextToImageApiController.php @@ -40,6 +40,7 @@ use OCP\DB\Exception; use OCP\Files\NotFoundException; use OCP\IL10N; use OCP\IRequest; +use OCP\TextToImage\Exception\TaskFailureException; use OCP\TextToImage\Exception\TaskNotFoundException; use OCP\TextToImage\Task; use OCP\TextToImage\IManager; @@ -95,7 +96,7 @@ class TextToImageApiController extends \OCP\AppFramework\OCSController { try { try { $this->textToImageManager->runOrScheduleTask($task); - } catch (\RuntimeException) { + } catch (TaskFailureException) { // noop } diff --git a/lib/private/TextToImage/Manager.php b/lib/private/TextToImage/Manager.php index eb3ee25b8e0..12f7db44a25 100644 --- a/lib/private/TextToImage/Manager.php +++ b/lib/private/TextToImage/Manager.php @@ -32,6 +32,7 @@ use OCP\Files\IAppData; use OCP\Files\NotFoundException; use OCP\Files\NotPermittedException; use OCP\IConfig; +use OCP\TextToImage\Exception\TaskFailureException; use OCP\TextToImage\Exception\TaskNotFoundException; use OCP\TextToImage\IManager; use OCP\TextToImage\Task; @@ -194,15 +195,11 @@ class Manager implements IManager { } catch (Exception $e) { $this->logger->warning('Failed to update database after Text2Image error', ['exception' => $e]); } - if ($e instanceof RuntimeException) { - throw $e; - } else { - throw new RuntimeException('Text2Image generation using provider "' . $provider->getName() . '" failed: ' . $e->getMessage(), 0, $e); - } + throw new TaskFailureException('Text2Image generation using provider "' . $provider->getName() . '" failed: ' . $e->getMessage(), 0, $e); } } - throw new RuntimeException('Could not run task'); + throw new TaskFailureException('Could not run task'); } /** diff --git a/lib/public/TextToImage/Exception/TaskFailureException.php b/lib/public/TextToImage/Exception/TaskFailureException.php new file mode 100644 index 00000000000..a640fdff2e8 --- /dev/null +++ b/lib/public/TextToImage/Exception/TaskFailureException.php @@ -0,0 +1,31 @@ + + * + * @author Marcel Klehr + * + * @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 . + * + */ + +namespace OCP\TextToImage\Exception; + +/** + * @since 28.0.0 + */ +class TaskFailureException extends TextToImageException { +} diff --git a/lib/public/TextToImage/IManager.php b/lib/public/TextToImage/IManager.php index cfe38e3ce7f..bc16896b43b 100644 --- a/lib/public/TextToImage/IManager.php +++ b/lib/public/TextToImage/IManager.php @@ -28,6 +28,7 @@ namespace OCP\TextToImage; use OCP\DB\Exception; use OCP\PreConditionNotMetException; +use OCP\TextToImage\Exception\TaskFailureException; use OCP\TextToImage\Exception\TaskNotFoundException; use RuntimeException; @@ -51,7 +52,7 @@ interface IManager { /** * @param Task $task The task to run * @throws PreConditionNotMetException If no or not the requested provider was registered but this method was still called - * @throws RuntimeException If something else failed + * @throws TaskFailureException If something else failed * @since 28.0.0 */ public function runTask(Task $task): void; @@ -71,7 +72,7 @@ interface IManager { /** * @throws Exception if there was a problem inserting the task into the database * @throws PreConditionNotMetException if no provider is registered - * @throws RuntimeException If the task run fail + * @throws TaskFailureException If the task run failed * @since 28.0.0 */ public function runOrScheduleTask(Task $task) : void;