en(TextToImage): Use specific exception class instead of generic RuntimeException

Signed-off-by: Marcel Klehr <mklehr@gmx.net>
pull/40326/head
Marcel Klehr 7 months ago
parent 8339b5b128
commit 47e13cd55b

@ -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
}

@ -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');
}
/**

@ -0,0 +1,31 @@
<?php
/**
* @copyright Copyright (c) 2023 Marcel Klehr <mklehr@gmx.net>
*
* @author Marcel Klehr <mklehr@gmx.net>
*
* @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 OCP\TextToImage\Exception;
/**
* @since 28.0.0
*/
class TaskFailureException extends TextToImageException {
}

@ -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;

Loading…
Cancel
Save