An exception that will turn into an HTTP error response.
| 632 | |
| 633 | |
| 634 | class HTTPError(Exception): |
| 635 | """An exception that will turn into an HTTP error response.""" |
| 636 | def __init__(self, status_code, log_message=None, *args): |
| 637 | self.status_code = status_code |
| 638 | self.log_message = log_message |
| 639 | self.args = args |
| 640 | |
| 641 | def __str__(self): |
| 642 | message = "HTTP %d: %s" % ( |
| 643 | self.status_code, http.client.responses[self.status_code]) |
| 644 | if self.log_message: |
| 645 | return message + " (" + (self.log_message % self.args) + ")" |
| 646 | else: |
| 647 | return message |
| 648 | |
| 649 | |
| 650 | class ErrorHandler(RequestHandler): |