Skip to content

Commit

Permalink
Merge pull request #829 from MasoniteFramework/fix/659
Browse files Browse the repository at this point in the history
Refactor RouteProvider to handle exceptions and set response status t…
  • Loading branch information
josephmancuso authored Oct 24, 2024
2 parents fc44a6b + 93a9351 commit 5ba75e6
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/masonite/authorization/Gate.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ def inspect(self, permission, *args):
if boolean_result:
return AuthorizationResponse.allow()
else:
self.application.make("response").status(403)
return AuthorizationResponse.deny()

def check(self, permission, *args):
Expand Down
2 changes: 2 additions & 0 deletions src/masonite/dumps/Dumper.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@ def clear(self):

def dd(self, *objects):
"""Dump all provided args and die, raising a DumpException."""
self.app.make('response').status(200)
self._dump(*objects)
raise DumpException()

def dump(self, *objects):
"""Dump all provided args and continue code execution. This does not raise a DumpException."""
self.app.make('response').status(200)
dumps = self._dump(*objects)
# output dumps in console
for dump in dumps:
Expand Down
1 change: 1 addition & 0 deletions src/masonite/exceptions/handlers/ModelNotFoundHandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ def handle(self, exception):
masonite_exception = ModelNotFoundException(
"No record found with the given primary key"
)
self.application.make("response").status(404)
self.application.make("exception_handler").handle(masonite_exception)
2 changes: 2 additions & 0 deletions src/masonite/providers/RouteProvider.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ def boot(self):
else:
response.view(data)
except Exception as e:
if not response.get_status_code():
response.status(500)
exception = e

self.application.make("middleware").run_route_middleware(
Expand Down

0 comments on commit 5ba75e6

Please sign in to comment.