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 6ab1891
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 11 deletions.
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"symfony/messenger": "^5.4 || ^6.4 || ^7.0",
"symfony/options-resolver": "^5.4 || ^6.4 || ^7.0",
"symfony/routing": "^5.4 || ^6.4 || ^7.0",
"symfony/translation": "^5.4 || ^6.4 || ^7.0",
"webmozart/assert": "^1.11"
},
"require-dev": {
Expand Down
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) {
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()],
);
}

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 6ab1891

Please sign in to comment.