Skip to content

Commit

Permalink
Only add errors to the session if they exist
Browse files Browse the repository at this point in the history
  • Loading branch information
circulon committed Aug 22, 2024
1 parent 4892c1c commit 51ceb16
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/masonite/middleware/route/SessionMiddleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@ def before(self, request, response):
request.app.make("request").session = Session

# TODO: Remove in Masonite 5
bag = MessageBag(Session.get("errors") or {})
request.app.make("view").share({"errors": bag.helper})
errors = Session.get("errors") or {}
request.app.make("view").share({"errors": MessageBag(errors).helper})
# errors are stored in session flash so 'getting' them actually clears them
# so re-add them to the session as a MessageBag
Session.flash('errors', bag)
# if any then re-add them to the session
if errors:
Session.flash('errors', errors)
return request

def after(self, request, _):
Expand Down

0 comments on commit 51ceb16

Please sign in to comment.