Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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 2 changed files with 49 additions and 0 deletions. Show diff stats Hide diff stats

  1. +6 0 docs/exceptions.rst
  2. +43 0 werkzeug/exceptions.py
6 docs/exceptions.rst
Source Rendered
@@ -44,6 +44,12 @@ The following error classes exist in Werkzeug:
44 44
45 45 .. autoexception:: ImATeapot
46 46
  47 +.. autoexception:: PreconditionRequired
  48 +
  49 +.. autoexception:: TooManyRequests
  50 +
  51 +.. autoexception:: RequestHeaderFieldsTooLarge
  52 +
47 53 .. autoexception:: InternalServerError
48 54
49 55 .. autoexception:: NotImplemented
43 werkzeug/exceptions.py
@@ -436,6 +436,49 @@ class UnprocessableEntity(HTTPException):
436 436 '<p>The request was well-formed but was unable to be followed due to semantic errors.'
437 437 )
438 438
  439 +class PreconditionRequired(HTTPException):
  440 + """*428* `Precondition Required`
  441 +
  442 + The server requires this request to be conditional, typically to prevent
  443 + the lost update problem, which is a race condition between two or more
  444 + clients attempting to update a resource through PUT or DELETE. By requiring
  445 + each client to include a conditional header ("If-Match" or "If-Unmodified-
  446 + Since") with the proper value retained from a recent GET request, the
  447 + server ensures that each client has at least seen the previous revision of
  448 + the resource.
  449 + """
  450 + code = 428
  451 + description = (
  452 + '<p>This request is required to be conditional; try using "If-Match" '
  453 + 'or "If-Unmodified-Since".'
  454 + )
  455 +
  456 +class TooManyRequests(HTTPException):
  457 + """*429* `Too Many Requests`
  458 +
  459 + The server is limiting the rate at which this user receives responses, and
  460 + this request exceeds that rate. (The server may use any convenient method
  461 + to identify users and their request rates). The server may include a
  462 + "Retry-After" header to indicate how long the user should wait before
  463 + retrying.
  464 + """
  465 + code = 429
  466 + description = (
  467 + '<p>This user has exceeded an allotted request count. Try again later.'
  468 + )
  469 +
  470 +class RequestHeaderFieldsTooLarge(HTTPException):
  471 + """*431* `RequestHeaderFieldsTooLarge`
  472 +
  473 + The server refuses to process the request because the header fields are too
  474 + large. One or more individual fields may be too large, or the set of all
  475 + headers is too large.
  476 + """
  477 + code = 431
  478 + description = (
  479 + '<p>One or more header fields exceeds the maximum size.'
  480 + )
  481 +
439 482
440 483 class InternalServerError(HTTPException):
441 484 """*500* `Internal Server Error`

0 comments on commit ff5fa21

Please sign in to comment.
Something went wrong with that request. Please try again.