Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error Handlers versus Werkzeug Exceptions #175

Closed
mitsuhiko opened this issue Feb 17, 2011 · 4 comments
Closed

Error Handlers versus Werkzeug Exceptions #175

mitsuhiko opened this issue Feb 17, 2011 · 4 comments

Comments

@mitsuhiko
Copy link
Contributor

Currently you can only declare error handler for Werkzeug exceptions. That's pretty much the case because what is not raised as a Werkzeug HTTP exception can't be catched. However since Python 2.4 is currently in the process of being phased out we could now finally make exceptions actual response objects if we prefer so it would make sense to keep that in mind and provide catching not only by code but also by any kind of instance check.

This also affects Werkzeug.

Related feedback issues:

@adrianratnapala
Copy link

Perhaps I don't understand this issue, but maybe it should be closed. It seems like current flask versions allow error handlers for any kind of exception. By this I mean the following program runs without an error, there are all sorts of combinations and permutations which it doesn't test.

    import flask
    app = flask.Flask(__name__)

    @app.errorhandler(Exception)
    def handle_500(x=None):
            print "Trapped a python Exception!"
            return "app trapped", 200

    @app.route('/')
    def slash_view() :
            raise Exception("WTF?")

    c = app.test_client()
    resp = c.get('/')
    assert resp.data == "app trapped"
    assert resp.status_code == 200

@jeffwidman
Copy link
Contributor

@untitaker Is this still relevant?

I don't fully understand the original issue, and unfortunately the linked-to feedback site is now dead.

@untitaker
Copy link
Contributor

It's been a while, but I think the main idea here is to make HTTP exceptions fully fledged response objects. This is still valid.

The code for handling errors has been refactored to not make that much of a difference between HTTP and other exceptions, see #1291. But that's not the main point of this issue anyway.

@davidism davidism removed the feedback label Apr 19, 2017
@davidism
Copy link
Member

HTTPException is a WSGI callable, so make_response handles it fine. Not sure what else needs to be done here. If this is still an issue it needs to be clarified before reopening.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 14, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants