-
Notifications
You must be signed in to change notification settings - Fork 3
/
errors.py
49 lines (40 loc) · 1.3 KB
/
errors.py
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
47
48
49
from Log import Log
import traceback
class NoPerm(Exception):
pass
class WrongArgs(Exception):
pass
class NotFound(Exception):
pass
class ServerError(Exception):
pass
class OutOfRange(Exception):
pass
class Unauthorized(Exception):
pass
class error_handler:
def __init__(self, svc):
self.svc = svc
def __enter__(self):
pass
def __exit__(self, type, value, tb):
if (value == None):
return True
if (isinstance(value, NoPerm)):
self.svc.return_error(403, value.args[0])
elif (isinstance(value, WrongArgs)):
self.svc.return_error(400, value.args[0])
elif (isinstance(value, Unauthorized)):
self.svc.return_error(401, value.args[0])
elif (isinstance(value, NotFound)):
self.svc.return_error(404, value.args[0])
elif (isinstance(value, OutOfRange)):
self.svc.return_error(416, value.args[0])
elif (isinstance(value, ServerError)):
self.svc.return_error(500, value.args[0])
else:
info = "".join(traceback.format_exception(type, value, tb))
Log.error("Unexpected exception! %s" % info)
self.svc.return_error(500, "Unexpected server exception", info);
return False
return True