From acb3775bf3d70c09154333e7b5a5a8c1c7805e43 Mon Sep 17 00:00:00 2001 From: mesilov Date: Sun, 21 Apr 2024 01:37:32 +0600 Subject: [PATCH] Add new specific workflow exceptions Two new specific exceptions have been added, 'ActivityOrRobotAlreadyInstalledException' and 'ActivityOrRobotValidationFailureException' in the workflow services. These exceptions are to be thrown in situations where an activity or robot is already installed or fails validation. This improves error handling by distinguishing specific scenarios during the API's error handling process. Signed-off-by: mesilov --- src/Core/ApiLevelErrorHandler.php | 10 ++++++---- src/Core/Core.php | 10 ++++++++++ .../ActivityOrRobotAlreadyInstalledException.php | 9 +++++++++ .../ActivityOrRobotValidationFailureException.php | 9 +++++++++ 4 files changed, 34 insertions(+), 4 deletions(-) create mode 100644 src/Services/Workflows/Exceptions/ActivityOrRobotAlreadyInstalledException.php create mode 100644 src/Services/Workflows/Exceptions/ActivityOrRobotValidationFailureException.php diff --git a/src/Core/ApiLevelErrorHandler.php b/src/Core/ApiLevelErrorHandler.php index b25deae..dd2232b 100644 --- a/src/Core/ApiLevelErrorHandler.php +++ b/src/Core/ApiLevelErrorHandler.php @@ -8,14 +8,12 @@ use Bitrix24\SDK\Core\Exceptions\MethodNotFoundException; use Bitrix24\SDK\Core\Exceptions\OperationTimeLimitExceededException; use Bitrix24\SDK\Core\Exceptions\QueryLimitExceededException; +use Bitrix24\SDK\Services\Workflows\Exceptions\ActivityOrRobotAlreadyInstalledException; +use Bitrix24\SDK\Services\Workflows\Exceptions\ActivityOrRobotValidationFailureException; use Psr\Log\LoggerInterface; /** * Handle api-level errors and throw related exception - * - * Class ApiLevelErrorHandler - * - * @package Bitrix24\SDK\Core */ class ApiLevelErrorHandler { @@ -90,6 +88,10 @@ private function handleError(array $responseBody, ?string $batchCommandId = null throw new MethodNotFoundException(sprintf('api method not found %s %s', $errorDescription, $batchErrorPrefix)); case 'operation_time_limit': throw new OperationTimeLimitExceededException(sprintf('operation time limit exceeded %s %s', $errorDescription, $batchErrorPrefix)); + case 'error_activity_already_installed': + throw new ActivityOrRobotAlreadyInstalledException(sprintf('%s - %s', $errorCode, $errorDescription)); + case 'error_activity_validation_failure': + throw new ActivityOrRobotValidationFailureException(sprintf('%s - %s', $errorCode, $errorDescription)); default: throw new BaseException(sprintf('%s - %s %s', $errorCode, $errorDescription, $batchErrorPrefix)); } diff --git a/src/Core/Core.php b/src/Core/Core.php index 7351139..979aa78 100644 --- a/src/Core/Core.php +++ b/src/Core/Core.php @@ -108,6 +108,16 @@ public function call(string $apiMethod, array $parameters = []): Response // dispatch event, application listeners update domain url host in accounts repository $this->eventDispatcher->dispatch(new PortalDomainUrlChangedEvent($portalOldDomainUrlHost, $portalNewDomainUrlHost)); break; + case StatusCodeInterface::STATUS_BAD_REQUEST: + $body = $apiCallResponse->toArray(false); + $this->logger->notice( + 'bad request', + [ + 'body' => $body, + ] + ); + $this->apiLevelErrorHandler->handle($body); + break; case StatusCodeInterface::STATUS_UNAUTHORIZED: $body = $apiCallResponse->toArray(false); $this->logger->debug( diff --git a/src/Services/Workflows/Exceptions/ActivityOrRobotAlreadyInstalledException.php b/src/Services/Workflows/Exceptions/ActivityOrRobotAlreadyInstalledException.php new file mode 100644 index 0000000..bb3ee0e --- /dev/null +++ b/src/Services/Workflows/Exceptions/ActivityOrRobotAlreadyInstalledException.php @@ -0,0 +1,9 @@ +