diff --git a/packages/http/src/Session/FormSession.php b/packages/http/src/Session/FormSession.php index 02ab623bb..e349a12cf 100644 --- a/packages/http/src/Session/FormSession.php +++ b/packages/http/src/Session/FormSession.php @@ -17,7 +17,7 @@ private const string ORIGINAL_VALUES_KEY = '#original_values'; public function __construct( - private Session $session, + private(set) Session $session, ) {} /** diff --git a/packages/router/src/Exceptions/HtmlExceptionRenderer.php b/packages/router/src/Exceptions/HtmlExceptionRenderer.php index 01a2c570c..e4bf13fbc 100644 --- a/packages/router/src/Exceptions/HtmlExceptionRenderer.php +++ b/packages/router/src/Exceptions/HtmlExceptionRenderer.php @@ -14,6 +14,7 @@ use Tempest\Http\SensitiveField; use Tempest\Http\Session\FormSession; use Tempest\Http\Session\Session; +use Tempest\Http\Session\SessionManager; use Tempest\Http\Status; use Tempest\Intl\Translator; use Tempest\Reflection\ClassReflector; @@ -104,6 +105,10 @@ private function shouldRenderDevelopmentException(Throwable $throwable): bool return false; } + if ($throwable instanceof ValidationFailed) { + return false; + } + if (! $throwable instanceof HttpRequestFailed) { return true; } @@ -128,6 +133,7 @@ private function renderValidationFailedResponse(ValidationFailed $exception): Re if ($this->container->has(Session::class)) { $this->container->get(FormSession::class)->setErrors($exception->failingRules); $this->container->get(FormSession::class)->setOriginalValues($this->filterSensitiveFields($this->request, $exception->targetClass)); + $this->container->get(SessionManager::class)->save($this->container->get(FormSession::class)->session); } $errors = Arr\map($exception->failingRules, fn (array $failingRulesForField, string $field) => Arr\map(