Files
deb-python-falcon/docs/api/errors.rst
Kurt Griffiths a14a4b1b4a docs(errors): Update error class docstrings per the latest RFCs (#887)
Update error class docstrings to reflect the latest RFCs, and
add kwargs to more clearly communicate which HTTPError kwargs can
be used for each error class.

Fixes #595
2016-09-07 15:18:10 -06:00

1.8 KiB

Error Handling

When a request results in an error condition, you can manually set the error status, appropriate response headers, and even an error body using the resp object. However, Falcon tries to make things a bit easier and more consistent by providing a set of error classes you can raise from within your app. Falcon catches any exception that inherits from falcon.HTTPError, and automatically converts it to an appropriate HTTP response.

You may raise an instance of falcon.HTTPError directly, or use any one of a number of predefined error classes that try to be idiomatic in setting appropriate headers and bodies.

All classes are available directly from the falcon package namespace:

import falcon

class MessageResource(object):
    def on_get(self, req, resp):

        # ...

        raise falcon.HTTPBadRequest(
            'TTL Out of Range',
            'The message's TTL must be between 60 and 300 seconds, inclusive.'
        )

        # ...

Base Class

falcon.HTTPError

Mixins

falcon.http_error.NoRepresentation

Predefined Errors

falcon