Skip to content

Commit

Permalink
Fix bug where wrong object was being sent to the workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
loevgaard committed Jun 24, 2024
1 parent 63199d2 commit edf5dde
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions src/Message/CommandHandler/ProcessUploadOrderRequestHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ final class ProcessUploadOrderRequestHandler
*/
public function __construct(
ManagerRegistry $managerRegistry,
private readonly ClientInterface $peakWMSClient,
private readonly ClientInterface $peakClient,
private readonly SalesOrderDataMapperInterface $salesOrderDataMapper,
private readonly WorkflowInterface $uploadOrderRequestWorkflow,
private readonly string $uploadOrderRequestClass,
Expand Down Expand Up @@ -56,21 +56,21 @@ public function __invoke(ProcessUploadOrderRequest $message): void
$salesOrder = new SalesOrder();
$this->salesOrderDataMapper->map($order, $salesOrder);

$response = $this->peakWMSClient->salesOrder()->create($salesOrder);
$response = $this->peakClient->salesOrder()->create($salesOrder);
$uploadOrderRequest->setPeakOrderId($response->id);
$this->uploadOrderRequestWorkflow->apply($order, UploadOrderRequestWorkflow::TRANSITION_UPLOAD);
$this->uploadOrderRequestWorkflow->apply($uploadOrderRequest, UploadOrderRequestWorkflow::TRANSITION_UPLOAD);
} catch (\Throwable $e) {
$uploadOrderRequest->setError($e->getMessage());

$this->uploadOrderRequestWorkflow->apply($order, UploadOrderRequestWorkflow::TRANSITION_FAIL);
$this->uploadOrderRequestWorkflow->apply($uploadOrderRequest, UploadOrderRequestWorkflow::TRANSITION_FAIL);

throw new UnrecoverableMessageHandlingException(
message: sprintf('Failed to process upload order request with id %d', $message->uploadOrderRequest),
previous: $e,
);
} finally {
$uploadOrderRequest->setRequest(self::stringifyMessage($this->peakWMSClient->getLastRequest()));
$uploadOrderRequest->setResponse(self::stringifyMessage($this->peakWMSClient->getLastResponse()));
$uploadOrderRequest->setRequest(self::stringifyMessage($this->peakClient->getLastRequest()));
$uploadOrderRequest->setResponse(self::stringifyMessage($this->peakClient->getLastResponse()));
$manager->flush();
}
}
Expand All @@ -91,6 +91,7 @@ private static function stringifyMessage(RequestInterface|ResponseInterface|null
);
}

// todo mask authorization header
foreach ($message->getHeaders() as $name => $values) {
$result .= sprintf("%s: %s\n", $name, implode(', ', $values));
}
Expand Down

0 comments on commit edf5dde

Please sign in to comment.