masonite
masonite copied to clipboard
Route/HTTP middleware after method should execute after exception generate [#tara-label-bug]
Describe the bug
Create Route or Http Middleware to calculate response time with status code and route info for example:
datas = []
class RouteMiddleware:
route = {}
def before(self, request, response):
route.update({'start': datetime.now(), 'name': request.route.url})
def after(self, request, response):
route.update({'end':datetime.now(), 'status': response.get_status()})
datas.append(route)
Register above middleware in Kernel in http_middleware or route_middleware.web, and if one of controller gives exception then it will give None value in status. Which is not accurate.
Expected behaviour
response.get_status() should return 500 rather then None.
Steps to reproduce the bug
No response
Screenshots
No response
OS
macOS
OS version
Monterey 12.2
Browser
No response
Masonite Version
4.6.1
Anything else ?
No response
The after method of the middleware should be called after the success or error response has been generated.
@smurf-U what are you trying to do? Maybe a middleware is not the best place for this
@josephmancuso Trying to figure out how long it takes to process a route and if it is successful or not.
understood thanks