Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add exception docs #3490

Merged
merged 5 commits into from
Jan 6, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES/3490.doc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add documentation for ``aiohttp.web.HTTPException``.
1 change: 1 addition & 0 deletions docs/spelling_wordlist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ impl
incapsulates
Indices
infos
initializer
inline
intaking
io
Expand Down
40 changes: 37 additions & 3 deletions docs/web_reference.rst
Original file line number Diff line number Diff line change
Expand Up @@ -805,8 +805,8 @@ Response
^^^^^^^^

.. class:: Response(*, body=None, status=200, reason=None, text=None, \
headers=None, content_type=None, charset=None, zlib_executor_size=sentinel,
zlib_executor=None)
headers=None, content_type=None, charset=None, \
zlib_executor_size=sentinel, zlib_executor=None)

The most usable response class, inherited from :class:`StreamResponse`.

Expand Down Expand Up @@ -1207,7 +1207,7 @@ WebSocketReady


json_response
-------------
^^^^^^^^^^^^^

.. function:: json_response([data], *, text=None, body=None, \
status=200, reason=None, headers=None, \
Expand All @@ -1218,6 +1218,40 @@ Return :class:`Response` with predefined ``'application/json'``
content type and *data* encoded by ``dumps`` parameter
(:func:`json.dumps` by default).

HTTP Exceptions
^^^^^^^^^^^^^^^
Errors can also be returned by raising a HTTP exception instance from within
the handler.

.. class:: HTTPException(*, headers=None, reason=None, text=None, content_type=None)

Low-level HTTP failure.

:param headers: headers for the response
:type headers: dict or multidict.CIMultiDict

:param str reason: reason included in the response

:param str text: response's body

:param str content_type: response's content type. This is passed through
to the :class:`Response` initializer.

Sub-classes of ``HTTPException`` exist for the standard HTTP response codes
as described in :ref:`aiohttp-web-exceptions` and the expected usage is to
simply raise the appropriate exception type to respond with a specific HTTP
response code.

Since ``HTTPException`` is a sub-class of :class:`Response`, it contains the
methods and properties that allow you to directly manipulate details of the
response.

.. attribute:: status_code

HTTP status code for this exception class. This attribute is usually
defined at the class level. ``self.status_code`` is passed to the
:class:`Response` initializer.


.. _aiohttp-web-app-and-router:

Expand Down