Skip to content

Commit e49cdc4

Browse files
authored
PS-920 catch all integration errors (#632)
1 parent 89835ce commit e49cdc4

File tree

7 files changed

+51
-12
lines changed

7 files changed

+51
-12
lines changed

databox/api/src/Api/OutputTransformer/WorkspaceIntegrationOutputTransformer.php

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,17 @@ public function transform(object $data, string $outputClass, array &$context = [
8181
$output->setData($subData);
8282
}
8383

84-
$config = $this->integrationManager->getIntegrationConfiguration($data);
85-
$integration = $config->getIntegration();
86-
$output->integrationTitle = $integration->getTitle();
87-
$output->setConfig($integration->resolveClientConfiguration($data, $config));
84+
try {
85+
$config = $this->integrationManager->getIntegrationConfiguration($data);
86+
$integration = $config->getIntegration();
87+
$output->integrationTitle = $integration->getTitle();
88+
$output->setConfig($integration->resolveClientConfiguration($data, $config));
89+
} catch (\Throwable $e) {
90+
$output->lastErrors ??= [];
91+
$output->lastErrors[] = [
92+
'message' => $e->getMessage(),
93+
];
94+
}
8895

8996
if ($this->isGranted(AbstractVoter::EDIT, $data)) {
9097
$output->configYaml = Yaml::dump($data->getConfig(), 4);

databox/api/src/Entity/Core/AttributeDefinition.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -564,4 +564,9 @@ public function validateInitialValues(ExecutionContextInterface $context): void
564564
}
565565
}
566566
}
567+
568+
public function getOwnerId(): ?string
569+
{
570+
return $this->getWorkspace()?->getOwnerId();
571+
}
567572
}

databox/api/src/Entity/Traits/ErrorDisableInterface.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,9 @@ public function getErrorCount(): int;
1818

1919
public function disableAfterErrors(): void;
2020

21+
public function isEnabled(): bool;
22+
2123
public function getWorkspace(): ?Workspace;
24+
25+
public function getOwnerId(): ?string;
2226
}

databox/api/src/Integration/Aws/Rekognition/AwsRekognitionIntegration.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use App\Integration\UserActionsIntegrationInterface;
1818
use App\Integration\WorkflowHelper;
1919
use App\Integration\WorkflowIntegrationInterface;
20+
use App\Notification\EntityDisableNotifyableException;
2021
use App\Storage\RenditionManager;
2122
use App\Workflow\Event\AssetIngestWorkflowEvent;
2223
use Symfony\Component\Config\Definition\Builder\NodeBuilder;
@@ -189,8 +190,12 @@ public function getNeededJobs(IntegrationConfig $config, IntegrationConfig $need
189190
}
190191

191192
if ($neededIntegrationConfig->getIntegration() instanceof RenditionIntegration) {
192-
$renditionDefinition = $this->renditionManager
193-
->getRenditionDefinitionByName($neededIntegrationConfig->getWorkspaceId(), $rendition);
193+
try {
194+
$renditionDefinition = $this->renditionManager
195+
->getRenditionDefinitionByName($neededIntegrationConfig->getWorkspaceId(), $rendition);
196+
} catch (\InvalidArgumentException $e) {
197+
throw new EntityDisableNotifyableException($config->getWorkspaceIntegration(), sprintf('Rendition "%s" not found', $rendition), sprintf('Rendition "%s" not found in workspace "%s"', $rendition, $neededIntegrationConfig->getWorkspaceIntegration()->getWorkspace()->getName()), $e->getCode(), $e);
198+
}
194199

195200
return [
196201
RenditionIntegration::getJobId(

databox/api/src/Notification/EntityDisableNotifyableException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public function __construct(
1717
$workspace = $this->entity->getWorkspace();
1818

1919
parent::__construct(
20-
$workspace?->getOwnerId(),
20+
$this->entity->getOwnerId(),
2121
$subject,
2222
$message.($appendWorkspace && $workspace ? ' (in workspace: '.$workspace?->getName().')' : ''),
2323
$code,

databox/api/src/Notification/ExceptionNotifier.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,19 @@ public function __construct(
1515

1616
public function notifyException(UserNotifyableException $exception): void
1717
{
18+
if ($exception instanceof EntityDisableNotifyableException) {
19+
if (!$exception->getEntity()->isEnabled()) {
20+
return;
21+
}
22+
23+
$this->errorDisableHandler->handleError($exception->getEntity(), $exception);
24+
}
25+
1826
foreach ($exception->getSubscribers() as $subscriber) {
1927
$this->notifier->notifyUser($subscriber, $exception->getNotificationId(), [
2028
'subject' => $exception->getSubject(),
2129
'message' => $exception->getMessage(),
2230
]);
2331
}
24-
25-
if ($exception instanceof EntityDisableNotifyableException) {
26-
$this->errorDisableHandler->handleError($exception->getEntity(), $exception);
27-
}
2832
}
2933
}

databox/api/src/Workflow/IntegrationWorkflowRepository.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@
1313
use App\Integration\FilterNeedIntegrationInterface;
1414
use App\Integration\IntegrationManager;
1515
use App\Integration\WorkflowIntegrationInterface;
16+
use App\Notification\ExceptionNotifier;
17+
use App\Notification\UserNotifyableException;
1618
use Doctrine\ORM\EntityManagerInterface;
19+
use Psr\Log\LoggerInterface;
1720

1821
final readonly class IntegrationWorkflowRepository implements WorkflowRepositoryInterface
1922
{
@@ -30,6 +33,8 @@ public function __construct(
3033
private EntityManagerInterface $em,
3134
private IntegrationManager $integrationManager,
3235
private WorkflowRepositoryInterface $decorated,
36+
private ExceptionNotifier $exceptionNotifier,
37+
private LoggerInterface $logger,
3338
) {
3439
}
3540

@@ -126,7 +131,16 @@ private function createIntegrationsToWorkflow(Workflow $workflow, string $worksp
126131

127132
$neededJobs = null;
128133
if ($integration instanceof FilterNeedIntegrationInterface && null !== $neededConfig) {
129-
$neededJobs = $integration->getNeededJobs($config, $neededConfig, $job);
134+
try {
135+
$neededJobs = $integration->getNeededJobs($config, $neededConfig, $job);
136+
} catch (UserNotifyableException $e) {
137+
$this->exceptionNotifier->notifyException($e);
138+
} catch (\Exception $e) {
139+
$this->logger->alert(
140+
sprintf('Error while getting needed jobs for integration "%s"', $workspaceIntegration->getWorkspaceId()),
141+
['exception' => $e]
142+
);
143+
}
130144
}
131145

132146
foreach ($jobMap[$workspaceIntegration->getId()] as $j) {

0 commit comments

Comments
 (0)