-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathsuite_exceptions.py
300 lines (235 loc) · 8.49 KB
/
suite_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
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
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
#######################################################################
# Suite PY is a simple Python client for SuiteCRM API.
# Copyright (C) 2017-2018 BTACTIC, SCCL
# Copyright (C) 2017-2018 Marc Sanchez Fauste
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#######################################################################
class SuiteException(Exception):
"""
Base class for SuiteCRM requests exceptions.
"""
def __init__(self, data):
"""
Creates an exception with the provided data.
:param dict[str, str] data: data that specifies the exception.
"""
if data:
self.name = data['name']
self.description = data['description']
self.number = data['number']
else:
self.name = "UnknownSuiteException"
self.description = "Unknown error"
self.number = 1012
def __str__(self):
return self.name + ': ' + self.description
@staticmethod
def get_suite_exception(result):
"""
Get a SuiteException from the error specified in the result of a failed API call.
:param ict[str, str] result: result of a failed API call.
:return: the SuiteException that represents the error of result.
:rtype: SuiteException
"""
if not result:
return UnknownSuiteException(result)
if result['number'] == 0:
return NoErrorException(result)
if result['number'] == 10:
return InvalidLoginException(result)
if result['number'] == 11:
return InvalidSessionIDException(result)
if result['number'] == 12:
return UserNotConfiguredException(result)
if result['number'] == 20:
return ModuleDoesNotExistException(result)
if result['number'] == 21:
return FileDoesNotExistException(result)
if result['number'] == 30:
return ModuleNotSupportedException(result)
if result['number'] == 31:
return RelationshipNotSupportedException(result)
if result['number'] == 40:
return AccessDeniedException(result)
if result['number'] == 50:
return DuplicateRecordsException(result)
if result['number'] == 51:
return NoRecordsException(result)
if result['number'] == 52:
return CannotAddOfflineClientException(result)
if result['number'] == 53:
return ClientDeactivatedException(result)
if result['number'] == 60:
return NumberOfSessionsExceededException(result)
if result['number'] == 61:
return UpgradeClientException(result)
if result['number'] == 70:
return AdminCredentialsRequiredException(result)
if result['number'] == 80:
return CustomFieldTypeNotSupportedException(result)
if result['number'] == 81:
return CustomFieldPropertyNotSuppliedException(result)
if result['number'] == 90:
return ResourceManagementErrorException(result)
if result['number'] == 1000:
return InvalidCallErrorException(result)
if result['number'] == 1001:
return InvalidDataFormatException(result)
if result['number'] == 1005:
return InvalidSetCampaignMergeDataException(result)
if result['number'] == 1009:
return PasswordExpiredException(result)
if result['number'] == 1012:
return LDAPAuthenticationFailedException(result)
return UnknownSuiteException(result)
class NoErrorException(SuiteException): # Number 0
"""
Exception raised when no error is specified.
"""
pass
class InvalidLoginException(SuiteException): # Number 10
"""
Exception raised when login is invalid.
"""
pass
class InvalidSessionIDException(SuiteException): # Number 11
"""
Exception raised when session is not valid.
"""
pass
class UserNotConfiguredException(SuiteException): # Number 12
"""
Exception raised when the authenticated user is not configured.
"""
pass
class InvalidPortalClientException(SuiteException): # Number 13
"""
Exception raised when portal client does not have authorized access.
"""
pass
class ModuleDoesNotExistException(SuiteException): # Number 20
"""
Exception raised when requested module is not available.
"""
pass
class FileDoesNotExistException(SuiteException): # Number 21
"""
Exception raised when the requested file does not exist on the server.
"""
pass
class ModuleNotSupportedException(SuiteException): # Number 30
"""
Exception raised when the requested action is not supported on a module.
"""
pass
class RelationshipNotSupportedException(SuiteException): # Number 31
"""
Exception raised when a relationship is not supported on a module.
"""
pass
class AccessDeniedException(SuiteException): # Number 40
"""
Exception raised when logged user does not have
permission to perform the requested action.
"""
pass
class DuplicateRecordsException(SuiteException): # Number 50
"""
Exception raised when duplicated records are found.
"""
pass
class NoRecordsException(SuiteException): # Number 51
"""
Exception raised when no records are found.
"""
pass
class CannotAddOfflineClientException(SuiteException): # Number 52
"""
Exception raised when is not possible to add offline client.
"""
pass
class ClientDeactivatedException(SuiteException): # Number 53
"""
Exception raised when a client offline instance has been deactivated.
"""
pass
class NumberOfSessionsExceededException(SuiteException): # Number 60
"""
Exception raised when max number of sessions is reached.
"""
pass
class UpgradeClientException(SuiteException): # Number 61
"""
Exception raised when upgrading an offline client.
"""
pass
class AdminCredentialsRequiredException(SuiteException): # Number 70
"""
Exception raised when the requested action can only be
performed by an account with administrator rights.
"""
pass
class CustomFieldTypeNotSupportedException(SuiteException): # Number 80
"""
Exception raised when a custom type is not supported.
"""
pass
class CustomFieldPropertyNotSuppliedException(SuiteException): # Number 81
"""
Exception raised when one or more properties are
missing for the supplied custom field type.
"""
pass
class ResourceManagementErrorException(SuiteException): # Number 90
"""
Exception raised when the resource query limit specified in config.php
has been exceeded during execution of the request.
"""
pass
class InvalidCallErrorException(SuiteException): # Number 1000
"""
Exception raised when the requested call is invalid for the given module.
"""
pass
class InvalidDataFormatException(SuiteException): # Number 1001
"""
Exception raised when the data of a request is invalid.
"""
pass
class InvalidSetCampaignMergeDataException(SuiteException): # Number 1005
"""
Exception raised when merge action status will not be updated,
because, campaign_id is null or no targets were selected.
"""
pass
class LockoutReachedException(SuiteException): # Number 1008
"""
Exception raised when you have been locked out of the Sugar
application and cannot log in using existing password.
"""
pass
class PasswordExpiredException(SuiteException): # Number 1009
"""
Exception raised when password of logged user is expired.
"""
pass
class LDAPAuthenticationFailedException(SuiteException): # Number 1012
"""
Exception raised when LDAP Authentication failed
but supplied password was already encrypted.
"""
pass
class UnknownSuiteException(SuiteException):
"""
Exception raised when the request error is unknown.
"""
pass