Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

allow custom messages for most errors

  • Loading branch information...
commit 832a66978269ed47d2960b53f9b346915da0fd18 1 parent 7a56082
@bflyblue authored
Showing with 15 additions and 15 deletions.
  1. +15 −15 web/webapi.py
View
30 web/webapi.py
@@ -132,20 +132,20 @@ def __init__(self, message=None):
class Unauthorized(HTTPError):
"""`401 Unauthorized` error."""
message = "unauthorized"
- def __init__(self):
+ def __init__(self, message=None):
status = "401 Unauthorized"
headers = {'Content-Type': 'text/html'}
- HTTPError.__init__(self, status, headers, self.message)
+ HTTPError.__init__(self, status, headers, message or self.message)
unauthorized = Unauthorized
class Forbidden(HTTPError):
"""`403 Forbidden` error."""
message = "forbidden"
- def __init__(self):
+ def __init__(self, message=None):
status = "403 Forbidden"
headers = {'Content-Type': 'text/html'}
- HTTPError.__init__(self, status, headers, self.message)
+ HTTPError.__init__(self, status, headers, message or self.message)
forbidden = Forbidden
@@ -189,50 +189,50 @@ def __init__(self, cls=None):
class NotAcceptable(HTTPError):
"""`406 Not Acceptable` error."""
message = "not acceptable"
- def __init__(self):
+ def __init__(self, message=None):
status = "406 Not Acceptable"
headers = {'Content-Type': 'text/html'}
- HTTPError.__init__(self, status, headers, self.message)
+ HTTPError.__init__(self, status, headers, message or self.message)
notacceptable = NotAcceptable
class Conflict(HTTPError):
"""`409 Conflict` error."""
message = "conflict"
- def __init__(self):
+ def __init__(self, message=None):
status = "409 Conflict"
headers = {'Content-Type': 'text/html'}
- HTTPError.__init__(self, status, headers, self.message)
+ HTTPError.__init__(self, status, headers, message or self.message)
conflict = Conflict
class Gone(HTTPError):
"""`410 Gone` error."""
message = "gone"
- def __init__(self):
+ def __init__(self, message=None):
status = '410 Gone'
headers = {'Content-Type': 'text/html'}
- HTTPError.__init__(self, status, headers, self.message)
+ HTTPError.__init__(self, status, headers, message or self.message)
gone = Gone
class PreconditionFailed(HTTPError):
"""`412 Precondition Failed` error."""
message = "precondition failed"
- def __init__(self):
+ def __init__(self, message=None):
status = "412 Precondition Failed"
headers = {'Content-Type': 'text/html'}
- HTTPError.__init__(self, status, headers, self.message)
+ HTTPError.__init__(self, status, headers, message or self.message)
preconditionfailed = PreconditionFailed
class UnsupportedMediaType(HTTPError):
"""`415 Unsupported Media Type` error."""
message = "unsupported media type"
- def __init__(self):
+ def __init__(self, message=None):
status = "415 Unsupported Media Type"
headers = {'Content-Type': 'text/html'}
- HTTPError.__init__(self, status, headers, self.message)
+ HTTPError.__init__(self, status, headers, message or self.message)
unsupportedmediatype = UnsupportedMediaType
@@ -522,4 +522,4 @@ def _debugwrite(x):
if __name__ == "__main__":
import doctest
- doctest.testmod()
+ doctest.testmod()
Please sign in to comment.
Something went wrong with that request. Please try again.