-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy patherrors.py
More file actions
267 lines (185 loc) · 7.34 KB
/
errors.py
File metadata and controls
267 lines (185 loc) · 7.34 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
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
"""Python user-defined exceptions for uplink errors"""
ERROR_INTERNAL = 0x02
ERROR_CANCELED = 0x03
ERROR_INVALID_HANDLE = 0x04
ERROR_TOO_MANY_REQUESTS = 0x05
ERROR_BANDWIDTH_LIMIT_EXCEEDED = 0x06
ERROR_STORAGE_LIMIT_EXCEEDED = 0x07
ERROR_SEGMENTS_LIMIT_EXCEEDED = 0x08
ERROR_PERMISSION_DENIED = 0x09
ERROR_BUCKET_NAME_INVALID = 0x10
ERROR_BUCKET_ALREADY_EXISTS = 0x11
ERROR_BUCKET_NOT_EMPTY = 0x12
ERROR_BUCKET_NOT_FOUND = 0x13
ERROR_OBJECT_KEY_INVALID = 0x20
ERROR_OBJECT_NOT_FOUND = 0x21
ERROR_UPLOAD_DONE = 0x22
ERROR_AUTH_DIAL_FAILED = 0x30
ERROR_REGISTER_ACCESS_FAILED = 0x31
ERROR_LIBUPLINK_SO_NOT_FOUND = 0x9999
"""_Error defines"""
class StorjException(Exception):
"""Base class for other exceptions
Attributes:
code -- error code
message -- error message
details -- error message from uplink-c
"""
def __init__(self, message, code, details):
self.message = message
self.code = code
self.details = details
super(StorjException, self).__init__()
def __str__(self):
return repr(self.message)
class InternalError(StorjException):
"""Exception raised if internal error occurred.
Attributes:
details -- error message from uplink-c
"""
def __init__(self, details):
super().__init__("internal error", ERROR_INTERNAL, details)
class CancelledError(StorjException):
"""Exception raised if operation cancelled.
Attributes:
details -- error message from uplink-c
"""
def __init__(self, details):
super().__init__("operation canceled", ERROR_CANCELED, details)
class InvalidHandleError(StorjException):
"""Exception raised if handle is invalid.
Attributes:
details -- error message from uplink-c
"""
def __init__(self, details):
super().__init__("invalid handle", ERROR_INVALID_HANDLE, details)
class TooManyRequestsError(StorjException):
"""Exception raised if too many requests performed.
Attributes:
details -- error message from uplink-c
"""
def __init__(self, details):
super().__init__("too many requests", ERROR_TOO_MANY_REQUESTS, details)
class BandwidthLimitExceededError(StorjException):
"""Exception raised if allowed bandwidth limit exceeded.
Attributes:
details -- error message from uplink-c
"""
def __init__(self, details):
super().__init__("bandwidth limit exceeded", ERROR_BANDWIDTH_LIMIT_EXCEEDED, details)
class StorageLimitExceededError(StorjException):
"""Exception raised if allowed storage limit exceeded.
Attributes:
details -- error message from uplink-c
"""
def __init__(self, details):
super().__init__("storage limit exceeded", ERROR_STORAGE_LIMIT_EXCEEDED, details)
class SegmentsLimitExceededError(StorjException):
"""Exception raised if allowed segments limit exceeded.
Attributes:
details -- error message from uplink-c
"""
def __init__(self, details):
super().__init__("segments limit exceeded", ERROR_SEGMENTS_LIMIT_EXCEEDED, details)
class PermissionDeniedError(StorjException):
"""Exception raised if permission denied.
Attributes:
details -- error message from uplink-c
"""
def __init__(self, details):
super().__init__("permission denied", ERROR_PERMISSION_DENIED, details)
class BucketNameInvalidError(StorjException):
"""Exception raised if bucket name is invalid.
Attributes:
details -- error message from uplink-c
"""
def __init__(self, details):
super().__init__("invalid bucket name", ERROR_BUCKET_NAME_INVALID, details)
class BucketAlreadyExistError(StorjException):
"""Exception raised if bucket already exist.
Attributes:
details -- error message from uplink-c
"""
def __init__(self, details):
super().__init__("bucket already exists", ERROR_BUCKET_ALREADY_EXISTS, details)
class BucketNotEmptyError(StorjException):
"""Exception raised if bucket is not empty.
Attributes:
details -- error message from uplink-c
"""
def __init__(self, details):
super().__init__("bucket is not empty", ERROR_BUCKET_NOT_EMPTY, details)
class BucketNotFoundError(StorjException):
"""Exception raised if bucket not found.
Attributes:
details -- error message from uplink-c
"""
def __init__(self, details):
super().__init__("bucket not found", ERROR_BUCKET_NOT_FOUND, details)
class ObjectKeyInvalidError(StorjException):
"""Exception raised if object key is invalid.
Attributes:
details -- error message from uplink-c
"""
def __init__(self, details):
super().__init__("invalid object key", ERROR_OBJECT_KEY_INVALID, details)
class ObjectNotFoundError(StorjException):
"""Exception raised if object not found.
Attributes:
details -- error message from uplink-c
"""
def __init__(self, details):
super().__init__("object not found", ERROR_OBJECT_NOT_FOUND, details)
class UploadDoneError(StorjException):
"""Exception raised if upload is complete.
Attributes:
details -- error message from uplink-c
"""
def __init__(self, details):
super().__init__("upload completed", ERROR_UPLOAD_DONE, details)
class AuthDialFailedError(StorjException):
"""Exception raised if failure to dial the Auth Service.
Attributes:
details -- error message from uplink-c
"""
def __init__(self, details):
super().__init__("Auth dial failed", ERROR_AUTH_DIAL_FAILED, details)
class RegisterAccessFailedError(StorjException):
"""Exception raised if failure to register access grant with Auth Service.
Attributes:
details -- error message from uplink-c
"""
def __init__(self, details):
super().__init__("register accees failed", ERROR_REGISTER_ACCESS_FAILED, details)
class LibUplinkSoError(StorjException):
"""Exception raised if reason is unknown.
Attributes:
code -- error code
details -- error message from uplink-c
"""
def __init__(self):
super().__init__("libuplinkc.so not found", ERROR_LIBUPLINK_SO_NOT_FOUND,
"Please follow \"https://github.com/storj-thirdparty"
"/uplink-python#option-2\" "
"to build libuplinkc.so manually.")
def _storj_exception(code, details):
switcher = {
ERROR_INTERNAL: InternalError,
ERROR_CANCELED: CancelledError,
ERROR_INVALID_HANDLE: InvalidHandleError,
ERROR_TOO_MANY_REQUESTS: TooManyRequestsError,
ERROR_BANDWIDTH_LIMIT_EXCEEDED: BandwidthLimitExceededError,
ERROR_STORAGE_LIMIT_EXCEEDED:StorageLimitExceededError,
ERROR_SEGMENTS_LIMIT_EXCEEDED:SegmentsLimitExceededError,
ERROR_PERMISSION_DENIED:PermissionDeniedError,
ERROR_BUCKET_NAME_INVALID: BucketNameInvalidError,
ERROR_BUCKET_ALREADY_EXISTS: BucketAlreadyExistError,
ERROR_BUCKET_NOT_EMPTY: BucketNotEmptyError,
ERROR_BUCKET_NOT_FOUND: BucketNotFoundError,
ERROR_OBJECT_KEY_INVALID: ObjectKeyInvalidError,
ERROR_OBJECT_NOT_FOUND: ObjectNotFoundError,
ERROR_UPLOAD_DONE: UploadDoneError,
ERROR_AUTH_DIAL_FAILED:AuthDialFailedError,
ERROR_REGISTER_ACCESS_FAILED:RegisterAccessFailedError,
}
return switcher.get(code, StorjException)(details=details)