Skip to content

Commit

Permalink
Output the error when failing to update the order
Browse files Browse the repository at this point in the history
  • Loading branch information
loevgaard committed Aug 16, 2024
1 parent c391ce8 commit 6bc0141
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
23 changes: 13 additions & 10 deletions src/Controller/EditOrderAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Session\Session;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Symfony\Component\Translation\TranslatableMessage;

final class EditOrderAction
{
Expand All @@ -28,38 +29,40 @@ public function __invoke(Request $request, int $id): Response
$this->orderUpdater->update($request, $id);
} catch (NewOrderWrongTotalException) {
return $this->addFlashAndRedirect(
'error',
'setono_sylius_order_edit.order_update.total_error',
'sylius_admin_order_update',
$id,
'error',
'setono_sylius_order_edit.order_update.total_error',
);
} catch (\Throwable) {
} catch (\Throwable $e) {

Check warning on line 37 in src/Controller/EditOrderAction.php

View check run for this annotation

Codecov / codecov/patch

src/Controller/EditOrderAction.php#L37

Added line #L37 was not covered by tests
return $this->addFlashAndRedirect(
'error',
'setono_sylius_order_edit.order_update.general_error',
'sylius_admin_order_update',
$id,
'error',
'setono_sylius_order_edit.order_update.general_error',
['%error%' => $e->getMessage()],

Check warning on line 43 in src/Controller/EditOrderAction.php

View check run for this annotation

Codecov / codecov/patch

src/Controller/EditOrderAction.php#L41-L43

Added lines #L41 - L43 were not covered by tests
);
}

return $this->addFlashAndRedirect(
'success',
'setono_sylius_order_edit.order_update.success',
'sylius_admin_order_show',
$id,
'success',
'setono_sylius_order_edit.order_update.success',
);
}

private function addFlashAndRedirect(
string $type,
string $message,
string $route,
int $orderId,
string $type,
string $message,
array $messageParameters = [],
): RedirectResponse {
$session = $this->requestStack->getSession();

if ($session instanceof Session) {
$session->getFlashBag()->add($type, $message);
$session->getFlashBag()->add($type, new TranslatableMessage($message, $messageParameters, 'flashes'));
}

return new RedirectResponse($this->router->generate($route, ['id' => $orderId]));
Expand Down
2 changes: 1 addition & 1 deletion src/Resources/translations/flashes.en.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
setono_sylius_order_edit:
order_update:
general_error: 'An error occurred while updating the order'
general_error: 'An error occurred while updating the order: %error%'
total_error: 'Order should not have bigger total than before editing'
success: 'Order has been successfully updated'

0 comments on commit 6bc0141

Please sign in to comment.