forked from conan-io/conan
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patherrors.py
95 lines (68 loc) · 1.89 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
'''
Exceptions raised and handled in Conan server.
These exceptions are mapped between server (as an HTTP response) and client
through the REST API. When an error happens in server its translated to an HTTP
error code that its sent to client. Client reads the server code and raise the
matching exception.
see return_plugin.py
'''
def format_conanfile_exception(scope, method, exception):
import sys
import traceback
msg = "%s: Error in %s() method" % (scope, method)
try:
tb = sys.exc_info()[2]
_, line, _, contents = traceback.extract_tb(tb, 2)[1]
msg += ", line %d\n\t%s" % (line, contents)
except:
pass
msg += "\n\t%s" % str(exception)
return msg
class ConanException(Exception):
"""
Generic conans exception
"""
pass
class InvalidNameException(ConanException):
pass
class ConanConnectionError(ConanException):
pass
class ConanOutdatedClient(ConanException):
pass
# Remote exceptions #
class InternalErrorException(ConanException):
"""
Generic 500 error
"""
pass
class RequestErrorException(ConanException):
"""
Generic 400 error
"""
pass
class AuthenticationException(ConanException): # 401
"""
401 error
"""
pass
class ForbiddenException(ConanException): # 403
"""
403 error
"""
pass
class NotFoundException(ConanException): # 404
"""
404 error
"""
pass
class UserInterfaceErrorException(RequestErrorException):
"""
420 error
"""
pass
EXCEPTION_CODE_MAPPING = {InternalErrorException: 500,
RequestErrorException: 400,
AuthenticationException: 401,
ForbiddenException: 403,
NotFoundException: 404,
UserInterfaceErrorException: 420}