Skip to content

Commit

Permalink
Merge pull request webpy#187 from bflyblue/master
Browse files Browse the repository at this point in the history
Optional message for HTTP Errors
  • Loading branch information
aaronsw committed Oct 26, 2012
2 parents 7a56082 + 832a669 commit 8af2c4a
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions web/webapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -522,4 +522,4 @@ def _debugwrite(x):

if __name__ == "__main__":
import doctest
doctest.testmod()
doctest.testmod()

0 comments on commit 8af2c4a

Please sign in to comment.