Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor RouteProvider to handle exceptions and set response status t… #829

Merged
merged 4 commits into from
Oct 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading