-
Notifications
You must be signed in to change notification settings - Fork 556
/
exceptions.py
executable file
·67 lines (41 loc) · 1.5 KB
/
exceptions.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import re
import grpc
class XrayError(Exception):
REGEXP = ...
def __init__(self, details):
self.details = details
class EmailExistsError(XrayError):
REGEXP = re.compile(r"User (.*) already exists.")
def __init__(self, details, email):
self.email = email
super().__init__(details)
class EmailNotFoundError(XrayError):
REGEXP = re.compile(r"User (.*) not found.")
def __init__(self, details, email):
self.email = email
super().__init__(details)
class TagNotFoundError(XrayError):
REGEXP = re.compile(r"handler not found: (.*)")
def __init__(self, details, tag):
self.tag = tag
super().__init__(details)
class ConnectionError(XrayError):
REGEXP = re.compile(r"Failed to connect to remote host|Socket closed|Broken pipe")
def __init__(self, details):
super().__init__(details)
class TimeoutError(XrayError):
REGEXP = re.compile(r"Deadline Exceeded")
def __init__(self, details):
super().__init__(details)
class UnknownError(XrayError):
def __init__(self, details=''):
super().__init__(details)
class RelatedError(XrayError):
def __new__(cls, error: grpc.RpcError):
details = error.details()
for e in (EmailExistsError, EmailNotFoundError, TagNotFoundError, ConnectionError, TimeoutError):
m = e.REGEXP.search(details)
if not m:
continue
return e(details, *m.groups())
return UnknownError(details)