masonite icon indicating copy to clipboard operation
masonite copied to clipboard

Route/HTTP middleware after method should execute after exception generate [#tara-label-bug]

Open smurf-U opened this issue 3 years ago • 4 comments

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

smurf-U avatar Jun 02 '22 14:06 smurf-U

The after method of the middleware should be called after the success or error response has been generated.

smurf-U avatar Jun 02 '22 14:06 smurf-U

@smurf-U what are you trying to do? Maybe a middleware is not the best place for this

josephmancuso avatar Jun 10 '22 03:06 josephmancuso

@josephmancuso Trying to figure out how long it takes to process a route and if it is successful or not.

smurf-U avatar Jun 13 '22 05:06 smurf-U

understood thanks

josephmancuso avatar Jun 13 '22 13:06 josephmancuso