Skip to content

Commit

Permalink
Handle too many requests exception
Browse files Browse the repository at this point in the history
  • Loading branch information
loevgaard committed Nov 27, 2024
1 parent 704578b commit 71f939c
Showing 1 changed file with 7 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ public function __invoke(ProcessUploadProductVariantRequest $message): void
throw new UnrecoverableMessageHandlingException(sprintf('Upload product variant request with id %d has been updated since it was tried to be processed', $message->uploadProductVariantRequest));
}

if ($uploadProductVariantRequest->getState() !== UploadProductVariantRequestInterface::STATE_PROCESSING) {
throw new UnrecoverableMessageHandlingException(sprintf('Upload product variant request with id %d is not in the processing state', $message->uploadProductVariantRequest));
}

$productVariant = $uploadProductVariantRequest->getProductVariant();
if (null === $productVariant) {
throw new UnrecoverableMessageHandlingException(sprintf('The upload product variant request with id %d does not have an associated product variant', $message->uploadProductVariantRequest));
Expand All @@ -66,10 +70,8 @@ public function __invoke(ProcessUploadProductVariantRequest $message): void

$this->uploadProductVariantRequestWorkflow->apply($uploadProductVariantRequest, UploadProductVariantRequestWorkflow::TRANSITION_UPLOAD);
} catch (TooManyRequestsException $e) {
$this->uploadProductVariantRequestWorkflow->apply($uploadProductVariantRequest, UploadProductVariantRequestWorkflow::TRANSITION_RESET);

throw new RecoverableMessageHandlingException(
message: sprintf('Failed to process upload product variant request with id %d', $message->uploadProductVariantRequest),
message: sprintf('There were too many requests to Peak WMS API when trying to process upload product variant request with id %d. The message will be retried later.', $message->uploadProductVariantRequest),
previous: $e,
);
} catch (\Throwable $e) {
Expand All @@ -88,6 +90,8 @@ public function __invoke(ProcessUploadProductVariantRequest $message): void
if ($manager->isOpen()) {
$manager->flush();
}

$message->version = $uploadProductVariantRequest->getVersion();
}
}
}

0 comments on commit 71f939c

Please sign in to comment.