Better reraising of exceptions
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Armin Ronacher · committed by Armin Ronacher · parent b51ecd7 · Browse files · 3 files·+37 added−2 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
3 files+37 added−2 removed
- other:+37 added−2 removed
Provenance
- Commit
086ecdb- Tree
a75cdc6- Author
Armin Ronacher <armin.ronacher@active-4.com>- Committer
Armin Ronacher <armin.ronacher@active-4.com>- Parent
b51ecd7
3 files changed+37 added−2 removed
modified:docs/config.rst+2 added-1 removed
238 unmodified lines239 even create your own script for sourcing that activates a virtualenv240 and exports the development configuration for you.241 - Use a tool like `fabric`_ in production to push code and242 configurations separately to the production server(s). For some243- details about how to do that, head over to the :ref:`deploy` pattern.243+ details about how to do that, head over to the244+ :ref:`fabric-deployment` pattern.245 246 .. _fabric: http://fabfile.org/modified:docs/extensiondev.rst+23 added
288 unmodified lines289 and bind their app to the extension in another file::290 291 manager.init_app(app)292 293+End-Of-Request Behavior294+-----------------------295+296+Due to the change in Flask 0.7 regarding functions that are run at the end297+of the request your extension will have to be extra careful there if it298+wants to continue to support older versions of Flask. The following299+pattern is a good way to support both::300+301+ def close_connection(response):302+ ctx = _request_ctx_stack.top303+ ctx.sqlite3_db.close()304+ return response305+306+ if hasattr(app, 'teardown_request'):307+ app.teardown_request(close_connection)308+ else:309+ app.after_request(close_connection)310+311+Strictly speaking the above code is wrong, because teardown functions are312+passed the exception and typically don't return anything. However because313+the return value is discarded this will just work assuming that the code314+in between does not touch the passed parameter.315+316 Learn from Others317 -----------------318 319 This documentation only touches the bare minimum for extension64 unmodified linesmodified:flask/app.py+12 added-1 removed
791 unmodified lines792 exists, a default 500 internal server error message is displayed.793 794 .. versionadded: 0.3795 """796+ exc_type, exc_value, tb = sys.exc_info()797+798 got_request_exception.send(self, exception=e)799 handler = self.error_handlers.get(500)800+801 if self.propagate_exceptions:802+ # if we want to repropagate the exception, we can attempt to803+ # raise it with the whole traceback in case we can do that804+ # (the function was actually called from the except part)805+ # otherwise, we just raise the error again806+ if exc_value is e:807+ raise exc_type, exc_value, tb808+ else:799- raise809+ raise e810+811 self.logger.exception('Exception on %s [%s]' % (812 request.path,813 request.method814 ))253 unmodified lines