Skip to content

Check error handlers for classes before HTTP status codes - #839

Merged
mitsuhiko merged 1 commit into
pallets:masterfrom
danielrichman:master
May 7, 2014
Merged

mitsuhiko merged 1 commit into
pallets:masterfrom
danielrichman:master

Conversation

@danielrichman

Copy link
Copy Markdown
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

bcambel commented Sep 14, 2013

Copy link
Copy Markdown

👍

@untitaker

Copy link
Copy Markdown
Contributor

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

@untitaker

Copy link
Copy Markdown
Contributor

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

@danielrichman

Copy link
Copy Markdown
Contributor Author

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

@untitaker

Copy link
Copy Markdown
Contributor

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

@untitaker

Copy link
Copy Markdown
Contributor

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

@DasIch

DasIch commented Sep 14, 2013

Copy link
Copy Markdown
Contributor

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
Copy Markdown
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

DasIch commented Sep 14, 2013

Copy link
Copy Markdown
Contributor

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
Copy Markdown
Contributor Author

CHANGES entry added

@singingwolfboy

Copy link
Copy Markdown
Contributor

Looks like a good idea to me

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

Copy link
Copy Markdown
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