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

Already on GitHub? Sign in to your account

Add HTTPExceptions for 428, 429, and 431 #200

Merged
merged 2 commits into from Jan 7, 2013
Jump to file or symbol
Failed to load files and symbols.
+52 −0
Split
View
@@ -44,6 +44,12 @@ The following error classes exist in Werkzeug:
.. autoexception:: ImATeapot
+.. autoexception:: PreconditionRequired
+
+.. autoexception:: TooManyRequests
+
+.. autoexception:: RequestHeaderFieldsTooLarge
+
.. autoexception:: InternalServerError
.. autoexception:: NotImplemented
View
@@ -65,6 +65,9 @@
423: 'Locked',
424: 'Failed Dependency',
426: 'Upgrade Required',
+ 428: 'Precondition Required', # see RFC 6585
+ 429: 'Too Many Requests',
+ 431: 'Request Header Fields Too Large',
449: 'Retry With', # proprietary MS extension
500: 'Internal Server Error',
501: 'Not Implemented',
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* `Request Header Fields Too Large`
+
+ 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`