Skip to content

Conversation

@danielrichman
Copy link
Contributor

This allows adding error handlers like this:

@app.errorhandler(werkzeug.exceptions.Forbidden)

And subclassing HTTPExceptions:

class ForbiddenBecauseReason(Forbidden): pass

@app.errorhandler(ForbiddenBecauseReason)
def error1():
    return "Forbidden because reason", 403

@app.errorhandler(403)
def error2():
    return "Forbidden", 403

... the idea being, that a flask extension might want to raise an exception, with the default behaviour of creating a HTTP error page, but still allowing the user to add a view/handler specific to that exception (e.g., "Forbidden because you are not in the right group").

@bcambel
Copy link

bcambel commented Sep 14, 2013

👍

@untitaker
Copy link
Contributor

Idea and execution looks good to me. Can you add tests though?

@untitaker
Copy link
Contributor

Eh, nevermind :P I guess i meant changelog entry.

@danielrichman
Copy link
Contributor Author

To /CHANGES? Which heading would you like me to add it under?

@untitaker
Copy link
Contributor

Yes, to CHANGES. I guess to 0.10.2, as it's a minor change.

@untitaker
Copy link
Contributor

I don't know if @mitsuhiko has anything against this change though. He is the one who makes decisions.

@DasIch
Copy link
Contributor

DasIch commented Sep 14, 2013

This isn't a bugfix so it's not going to land in 0.10.2. If it gets merged, it will be in 1.0 (because there won't be a 0.11.)

@untitaker
Copy link
Contributor

I thought it'd be sensible because from what i can remember smaller behavior changes have been added to bugfix releases. Can't recall if it was Werkzeug or Flask though.

@DasIch
Copy link
Contributor

DasIch commented Sep 14, 2013

I still don't think it's a good idea though, unless there is a very good reason for it. This definitely isn't one.

This allows adding error handlers like this:

    @app.errorhandler(werkzeug.exceptions.Forbidden)

And subclassing HTTPExceptions:

    class ForbiddenBecauseReason(Forbidden): pass

    @app.errorhandler(ForbiddenBecauseReason)
    def error1(): return "Forbidden because reason", 403
    @app.errorhandler(403)
    def error2(): return "Forbidden", 403

... the idea being, that a flask extension might want to raise an
exception, with the default behaviour of creating a HTTP error page,
but still allowing the user to add a view/handler specific to that
exception (e.g., "Forbidden because you are not in the right group").
@danielrichman
Copy link
Contributor Author

CHANGES entry added

@singingwolfboy
Copy link
Contributor

Looks like a good idea to me

@mitsuhiko mitsuhiko merged commit 3d67736 into pallets:master May 7, 2014
@mitsuhiko
Copy link
Contributor

Merged finally. It's a good idea.

@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.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants