Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Adding HTTPException subclasses for HTTP statuses 428, 429, and 431,

which were recently added in RFC 6585.
  • Loading branch information...
commit ff5fa21e5192da342ca84232baab864e349473e6 1 parent fe7633c
jessaustin authored
Showing with 49 additions and 0 deletions.
  1. +6 −0 docs/exceptions.rst
  2. +43 −0 werkzeug/exceptions.py
6 docs/exceptions.rst
View
@@ -44,6 +44,12 @@ The following error classes exist in Werkzeug:
.. autoexception:: ImATeapot
+.. autoexception:: PreconditionRequired
+
+.. autoexception:: TooManyRequests
+
+.. autoexception:: RequestHeaderFieldsTooLarge
+
.. autoexception:: InternalServerError
.. autoexception:: NotImplemented
43 werkzeug/exceptions.py
View
@@ -436,6 +436,49 @@ class UnprocessableEntity(HTTPException):
'<p>The request was well-formed but was unable to be followed due to semantic errors.'
)
+class PreconditionRequired(HTTPException):
+ """*428* `Precondition Required`
+
+ The server requires this request to be conditional, typically to prevent
+ the lost update problem, which is a race condition between two or more
+ clients attempting to update a resource through PUT or DELETE. By requiring
+ each client to include a conditional header ("If-Match" or "If-Unmodified-
+ Since") with the proper value retained from a recent GET request, the
+ server ensures that each client has at least seen the previous revision of
+ the resource.
+ """
+ code = 428
+ description = (
+ '<p>This request is required to be conditional; try using "If-Match" '
+ 'or "If-Unmodified-Since".'
+ )
+
+class TooManyRequests(HTTPException):
+ """*429* `Too Many Requests`
+
+ The server is limiting the rate at which this user receives responses, and
+ this request exceeds that rate. (The server may use any convenient method
+ to identify users and their request rates). The server may include a
+ "Retry-After" header to indicate how long the user should wait before
+ retrying.
+ """
+ code = 429
+ description = (
+ '<p>This user has exceeded an allotted request count. Try again later.'
+ )
+
+class RequestHeaderFieldsTooLarge(HTTPException):
+ """*431* `RequestHeaderFieldsTooLarge`
+
+ The server refuses to process the request because the header fields are too
+ large. One or more individual fields may be too large, or the set of all
+ headers is too large.
+ """
+ code = 431
+ description = (
+ '<p>One or more header fields exceeds the maximum size.'
+ )
+
class InternalServerError(HTTPException):
"""*500* `Internal Server Error`
Please sign in to comment.
Something went wrong with that request. Please try again.