@@ -815,3 +815,100 @@ Utilities
815
815
*MIME type * of uploaded file, ``'text/plain' `` by default.
816
816
817
817
.. seealso :: :ref:`aiohttp-web-file-upload`
818
+
819
+
820
+ Exceptions
821
+ -----------
822
+
823
+ :mod: `aiohttp.web ` defines exceptions for list of *HTTP status codes *.
824
+
825
+ Each class relates to a single HTTP status code. Each class is a
826
+ subclass of the :class: `~HTTPException `.
827
+
828
+ Those exceptions are derived from :class: `Response ` also, so you can
829
+ eighter return exception object from :ref: `aiohttp-web-handler ` or raise it.
830
+
831
+ The follow snippets are equals::
832
+
833
+ @asyncio.coroutine
834
+ def handler(request):
835
+ return aiohttp.web.HTTPFound(request, '/redirect')
836
+
837
+ and::
838
+
839
+ @asyncio.coroutine
840
+ def handler(request):
841
+ raise aiohttp.web.HTTPFound(request, '/redirect')
842
+
843
+
844
+ Each exception class has a status code according to :rfc: `2068 `:
845
+ codes with 100-300 are not really errors; 400s are client errors,
846
+ and 500s are server errors.
847
+
848
+ Http Exception hierarchy chart::
849
+
850
+ Exception
851
+ HTTPException
852
+ HTTPSuccessful
853
+ * 200 - HTTPOk
854
+ * 201 - HTTPCreated
855
+ * 202 - HTTPAccepted
856
+ * 203 - HTTPNonAuthoritativeInformation
857
+ * 204 - HTTPNoContent
858
+ * 205 - HTTPResetContent
859
+ * 206 - HTTPPartialContent
860
+ HTTPRedirection
861
+ * 300 - HTTPMultipleChoices
862
+ * 301 - HTTPMovedPermanently
863
+ * 302 - HTTPFound
864
+ * 303 - HTTPSeeOther
865
+ * 304 - HTTPNotModified
866
+ * 305 - HTTPUseProxy
867
+ * 307 - HTTPTemporaryRedirect
868
+ HTTPError
869
+ HTTPClientError
870
+ * 400 - HTTPBadRequest
871
+ * 401 - HTTPUnauthorized
872
+ * 402 - HTTPPaymentRequired
873
+ * 403 - HTTPForbidden
874
+ * 404 - HTTPNotFound
875
+ * 405 - HTTPMethodNotAllowed
876
+ * 406 - HTTPNotAcceptable
877
+ * 407 - HTTPProxyAuthenticationRequired
878
+ * 408 - HTTPRequestTimeout
879
+ * 409 - HTTPConflict
880
+ * 410 - HTTPGone
881
+ * 411 - HTTPLengthRequired
882
+ * 412 - HTTPPreconditionFailed
883
+ * 413 - HTTPRequestEntityTooLarge
884
+ * 414 - HTTPRequestURITooLong
885
+ * 415 - HTTPUnsupportedMediaType
886
+ * 416 - HTTPRequestRangeNotSatisfiable
887
+ * 417 - HTTPExpectationFailed
888
+ HTTPServerError
889
+ * 500 - HTTPInternalServerError
890
+ * 501 - HTTPNotImplemented
891
+ * 502 - HTTPBadGateway
892
+ * 503 - HTTPServiceUnavailable
893
+ * 504 - HTTPGatewayTimeout
894
+ * 505 - HTTPVersionNotSupported
895
+
896
+ All http exceptions has constructor like::
897
+
898
+ HTTPNotFound(request, *, headers=None, reason=None)
899
+
900
+ if other not directly specified. *headers * will be added to *default
901
+ response headers *.
902
+
903
+ Classes :class: `HTTPMultipleChoices `, :class: `HTTPMovedPermanently `,
904
+ :class: `HTTPFound `, :class: `HTTPSeeOther `, :class: `HTTPUseProxy `,
905
+ :class: `HTTPTemporaryRedirect ` has constructor signature like::
906
+
907
+ HTTPFound(request, location, *, headers=None, reason=None)
908
+
909
+ where *location * is value for *Location HTTP header *.
910
+
911
+ :class: `HTTPMethodNotAllowed ` constructed with pointing trial method
912
+ and list of allowed methods::
913
+
914
+ HTTPMethodNotAllowed(request, method, allowed_methods, *, headers=None, reason=None)
0 commit comments