fix error message

This commit is contained in:
Yourun-Proger 2021-11-19 23:09:38 +03:00 committed by David Lord
parent 7b0c82dfdc
commit 633449a36c
No known key found for this signature in database
GPG key ID: 7A1C87E3F5BC42A8
2 changed files with 11 additions and 1 deletions

View file

@ -130,7 +130,15 @@ def after_this_request(f: AfterRequestCallable) -> AfterRequestCallable:
.. versionadded:: 0.9
"""
_request_ctx_stack.top._after_request_functions.append(f)
top = _request_ctx_stack.top
if top is None:
raise RuntimeError(
"This decorator can only be used at local scopes "
"when a request context is on the stack. For instance within "
"view functions."
)
top._after_request_functions.append(f)
return f