Skip to content

Instantly share code, notes, and snippets.

@geekKeen
Last active January 31, 2018 03:35
Show Gist options
  • Save geekKeen/dda49cce7695e299c7aa5557609aa84c to your computer and use it in GitHub Desktop.
Save geekKeen/dda49cce7695e299c7aa5557609aa84c to your computer and use it in GitHub Desktop.
异常处理 / 自定义异常
class JobLookupError(KeyError):
def __init__(self, job_id):
super(KeyError, self).__init__(u'No job by the id of %s was found' % job_id)
raise JobLookupError(job_id)
class HTTPException(Exception):
code = None
description = None
def __init__(self, description=None, response=None):
Exception.__init__(self)
if description is not None:
self.description = description
self.response = response
class BadRequest(HTTPException):
code = 400
description = '...'
class ClientDisconnected(BadRequest):
pass
@geekKeen
Copy link
Author

类属性的使用方法
如果该类是可以继承的,且有默认的属性, 提出来做类属性 如 code 和 description

@geekKeen
Copy link
Author

HTTP 各状态码的含义

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment