Skip to content

Commit

Permalink
Add exception docs (#3490)
Browse files Browse the repository at this point in the history
* Fix aiohttp.web.Response docs.
* Adjust json_response TOC level.
* Add HTTPException class documentation.
  • Loading branch information
dave-shawley authored and asvetlov committed Jan 6, 2019
1 parent c9dabcb commit 3a0c7bf
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 3 deletions.
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

0 comments on commit 3a0c7bf

Please sign in to comment.