forked from qqj1228/Python_Blog
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAPIError.py
More file actions
44 lines (32 loc) · 1.04 KB
/
Copy pathAPIError.py
File metadata and controls
44 lines (32 loc) · 1.04 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
#!/usr/bin/env python3
# coding:utf-8
class APIError(Exception):
'''
The base APIError class which contains error(required), data(optional)
and message(optional).
'''
def __init__(self, error, data='', message=''):
super().__init__(message)
self.error = error
self.data = data
self.message = message
class APIValueError(APIError):
'''
Indicate the input value has error or invalid.
The data specifies the error field of input form.
'''
def __init__(self, field, message=''):
super().__init__('value:invalid', field, message)
class APIResourceNotFoundError(APIError):
'''
Indicate the resource was not found.
The data specifies the resource name.
'''
def __init__(self, field, message=''):
super().__init__('value:notfound', field, message)
class APIPermissionError(APIError):
'''
Indicate the api has no permission.
'''
def __init__(self, message=''):
super().__init__('permission:forbidden', 'permission', message)