Skip to content

Commit

Permalink
Add new specific workflow exceptions
Browse files Browse the repository at this point in the history
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 <mesilov.maxim@gmail.com>
  • Loading branch information
mesilov committed Apr 20, 2024
1 parent e752709 commit acb3775
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/Core/ApiLevelErrorHandler.php
Expand Up @@ -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
{
Expand Down Expand Up @@ -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));
}
Expand Down
10 changes: 10 additions & 0 deletions src/Core/Core.php
Expand Up @@ -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(
Expand Down
@@ -0,0 +1,9 @@
<?php

namespace Bitrix24\SDK\Services\Workflows\Exceptions;

use Bitrix24\SDK\Core\Exceptions\InvalidArgumentException;

class ActivityOrRobotAlreadyInstalledException extends InvalidArgumentException
{
}
@@ -0,0 +1,9 @@
<?php

namespace Bitrix24\SDK\Services\Workflows\Exceptions;

use Bitrix24\SDK\Core\Exceptions\InvalidArgumentException;

class ActivityOrRobotValidationFailureException extends InvalidArgumentException
{
}

0 comments on commit acb3775

Please sign in to comment.