-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy patherrorcode.py
More file actions
46 lines (34 loc) · 1.1 KB
/
errorcode.py
File metadata and controls
46 lines (34 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# -*- coding: utf-8 -*-
# @Author: theo-l
# @Date: 2017-06-30 14:08:08
# @Last Modified by: theo-l
# @Last Modified time: 2017-07-05 12:45:24
class ErrorCode(object):
def __init__(self, status_code, detail):
self._code = status_code
self._detail = detail
@property
def code(self):
return self._code
@property
def detail(self):
return self._detail
def __str__(self):
return str(self._code)
def __unicode__(self):
return self.__str__()
# common
UNKNOWN_ERROR = ErrorCode(-1, u'Unknown error!')
SUCCESS = ErrorCode(0, u'Success!')
REQUIRED = ErrorCode(1000, u"parameter required error!")
DUPLICATED = ErrorCode(1001, u"unique entry error!")
NOT_ALLOWED = ErrorCode(1002, u"action not allowed error!")
AUTH_NEEDED = ErrorCode(1003, u"unauthorized error!")
BAD_PARAMS = ErrorCode(1004, u" parameter error!")
NOT_EXISTS = ErrorCode(1005, u"object not exist error!")
EXPIRED = ErrorCode(1006, u'Data expired error!')
# auth error
# TODO
if __name__ == '__main__':
for code in (UNKNOWN_ERROR, SUCCESS):
print(code.code, code.detail)