Kitware / tangelo

A simple, quick, powerful web framework
http:/tangelohub.org/tangelo/
Apache License 2.0
185 stars 35 forks source link

Pass through cherrypy.HTTPRedirect exceptions #531

Closed manthey closed 8 years ago

manthey commented 8 years ago

In invoke_service, some exceptions should not be caught by the handler (currently on line 462). For instance, cherrypy.HTTPRedirect should be allowed to be raised so that when a return value with a Last-Modified header hasn't changed, the data need not be transferred to the caller.

Rather than except:, I'd recommend

except cherrypy.HTTPRedirect:
    raise
except Exception:
    tangelo.http_status(501, "Web Service Error")

There are other cherrypy exceptions that perhaps should also be raised. Candidates are cherrypy.HTTPError, which would allow services to just raise an explicit error to exit early, cherrypy.InternalRedirect, which might be usable to redirect to another endpoint, and cherrypy.NotFound, which would allow a service to return an explicit 404 to exit early.

waxlamp commented 8 years ago

I'd like to avoid exposing CherryPy through the Tangelo API.

Currently, you can "exit early" for errors and not found by saying tangelo.http_status(404) etc. followed by a return statement (which, if there is nothing to signal to the client, can simply be e.g. return None).

That leaves redirects. Would it be ok to create special functions like tangelo.internal_redirect() and tangelo.redirect() that could be used similarly to signal these cases? You would say return tangelo.redirect("/other/url") and the server infrastructure would turn it into the appropriate CherryPy logic.

@manthey let me know what you think.

manthey commented 8 years ago

I think having tangelo.redirect() and tangelo.internal_redirect are good way to do this.