You say “predicate/deriver” but those are two different things. Predicates will influence what view matches the request but do not modify the behavior of the view callable. If no view is found a 404 is raised.
View derivers do the opposite: They modify the behavior of the view callable but do not influence choosing the view. The default Pyramid permission view deriver will raise HTTP Forbidden if the permission check fails. I’m not familiar with Cornice so I can’t speak to anything there. — Theron > On Feb 14, 2025, at 3:26 AM, Thierry Florac <[email protected]> wrote: > > I tried to use permission predicate/deriver, but an HTTP NotFound exception > is raised if the permission is not granted to the current request! > I think that an HTTP Forbidden exception would be more appropriate to handle > automatic redirection to a login form from the client application... > > Best regards, > Thierry > -- > https://www.ulthar.net <https://www.ulthar.net/> -- > http://pyams.readthedocs.io <http://pyams.readthedocs.io/> > > Le jeu. 13 févr. 2025 à 23:37, Theron Luhn <[email protected] > <mailto:[email protected]>> a écrit : >> You might be looking for something like view derivers >> https://docs.pylonsproject.org/projects/pyramid/en/latest/narr/hooks.html#custom-view-derivers >> >> That will allow you to accept additional parameters in >> `add_view`/`@view_config` and wrap the view in customer behavior, such as >> raising an HTTPForbidden if a certain condition isn’t met. >> >> e.g. `permission` is implemented using a view deriver >> https://github.com/Pylons/pyramid/blob/eb0e01a0fd7aff84c345b1c43bd4fa9d2fe04441/src/pyramid/viewderivers.py#L286-L333 >> >> — Theron >> >> >> >>> On Feb 13, 2025, at 2:22 PM, Thierry Florac <[email protected] >>> <mailto:[email protected]>> wrote: >>> >>> Hi, >>> I'm building a REST API using Pyramid and Cornice for which I defined >>> custom view predicates. By default, an HTTP NotFound error is raised when a >>> predicate is not verified. Is there a way to raise a custom error, like an >>> HTTP Unauthorized or HTTP Forbidden? >>> >>> Best regards, >>> Thierry >>> -- >>> https://www.ulthar.net <https://www.ulthar.net/> -- >>> http://pyams.readthedocs.io <http://pyams.readthedocs.io/> >>> >>> -- >>> You received this message because you are subscribed to the Google Groups >>> "pylons-discuss" group. >>> To unsubscribe from this group and stop receiving emails from it, send an >>> email to [email protected] >>> <mailto:[email protected]>. >>> To view this discussion visit >>> https://groups.google.com/d/msgid/pylons-discuss/CAPX_VWAa46kYQZeh3-vsS5xB2XCrdL_P73xOew8xf-AgoefrNw%40mail.gmail.com >>> >>> <https://groups.google.com/d/msgid/pylons-discuss/CAPX_VWAa46kYQZeh3-vsS5xB2XCrdL_P73xOew8xf-AgoefrNw%40mail.gmail.com?utm_medium=email&utm_source=footer>. >> >> >> -- >> You received this message because you are subscribed to the Google Groups >> "pylons-discuss" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to [email protected] >> <mailto:[email protected]>. >> To view this discussion visit >> https://groups.google.com/d/msgid/pylons-discuss/4612BE66-D7F2-49FA-8B74-9FAC908097A1%40luhn.com >> >> <https://groups.google.com/d/msgid/pylons-discuss/4612BE66-D7F2-49FA-8B74-9FAC908097A1%40luhn.com?utm_medium=email&utm_source=footer>. > > > -- > You received this message because you are subscribed to the Google Groups > "pylons-discuss" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected] > <mailto:[email protected]>. > To view this discussion visit > https://groups.google.com/d/msgid/pylons-discuss/CAPX_VWC12Yp0kkoKsX5LwDJ6vBVSqMKeKErm0%3DR4Zn-W0_SD_g%40mail.gmail.com > > <https://groups.google.com/d/msgid/pylons-discuss/CAPX_VWC12Yp0kkoKsX5LwDJ6vBVSqMKeKErm0%3DR4Zn-W0_SD_g%40mail.gmail.com?utm_medium=email&utm_source=footer>. -- You received this message because you are subscribed to the Google Groups "pylons-discuss" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion visit https://groups.google.com/d/msgid/pylons-discuss/ED1B4B24-A442-4B99-801C-F7C994C19FB5%40luhn.com.
