Returning a 404 from wsme pecan extension

150 views
Skip to first unread message

James Slagle

unread,
Jul 14, 2013, 12:28:06 PM7/14/13
to pytho...@googlegroups.com

Hi,

Suppose you have a rest api (using pecan+wsme) and a non existent resource is requested such as
/api/books/2.  Looking at the latest wsexpose function in wsmeext.pecan, it looks like the way to return
a 404 to the client in this case would be something like the following from your controller method:

return wsme.api.Response(Book(), status_code=404)

That seems to work for getting a 404 in the client, but there's no way to pass a message as well, such as
"Book 2 Not Found".

The exception handler in the wsexpose function in wsmeext.pecan,  only returns unexpected
status codes for 400 or 500.  Is this where we could add the ability to handle a 404 (and perhaps other) exceptions? 
I'm thinking along the lines of adding more exception types to wsme/exc.py such as NotFound, etc, and
then checking for those in the exception handler in wsexpose, similar to how 'Client' is handled.

This would also make it such that unexpected errors could be handled the same way.  Whereas now
from your controller method if you want a 400, you raise a wsme.exc.ClientSideError, but if you want
a 404, you return a Response object with status_code of 404.

Any ideas about this?  Are there other plans to add handling of unexpected errors to the pecan extension?

Thanks!

James Slagle

Christophe de Vienne

unread,
Jul 24, 2013, 2:43:17 PM7/24/13
to pytho...@googlegroups.com
Hi James,

Sorry about the delay, I though your mail disappears from the moderation
list.

I answered your question on the issue 10 at
https://bitbucket.org/cdevienne/wsme/issue/10/returning-404-or-basically-any-status-code.

Basically there is a lack of control on the returned status code.
Historically it is because the initial implementation was thought as a
multi-protocol service, and the general philosophy moved to REST apis
wrapped in alternate protocols. Not all the needs are fulfilled yet, the
main issue remaining being the status code handling.

Regards,

Christophe

Le 14/07/2013 18:28, James Slagle a �crit :
> --
> You received this message because you are subscribed to the Google
> Groups "python-wsme" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to python-wsme...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>

Reply all
Reply to author
Forward
0 new messages