tg2
tg2 copied to clipboard
Route/HTTP middleware after method should execute after exception response generate
Describe the bug
Trying to figure out how long it takes to process a route and if it is successful or not. By creating dispatch controller wrapper to calculate response time with status code and route info for example:
datas = []
def controller_wrapper(next_caller):
route = {}
def call(*args, **kw):
try:
route.update({'start': datetime.now(), 'name': request.route.url})
print('Before handler!')
return next_caller(*args, **kw)
finally:
print('After Handler!')
route.update({'end':datetime.now(), 'status': response.get_status()})
datas.append(route)
print(":::::response", response.status_code, dir(response))
return call
config.get_component('dispatch').register_controller_wrapper(controller_wrapper)
After Register above wrapper, and if one of controller gives exception then it will give status_code
value as 200
. Which is not accurate.
Expected behaviour
response.status_code
should give 500
rather then None.
Version
turbogears2==2.4.3