You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: contentstack/errors.py
+55-72Lines changed: 55 additions & 72 deletions
Original file line number
Diff line number
Diff line change
@@ -23,39 +23,73 @@
23
23
"""
24
24
25
25
26
-
classError(Exception):
27
-
26
+
classError:
28
27
"""
29
28
contentstack.error
30
29
~~~~~~~~~~~~~~~~~~
31
30
This module implements the Error class.
32
31
API Reference: https://www.contentstack.com/docs/apis/content-delivery-api/#error
33
-
34
32
"""
35
33
36
34
def__init__(self):
37
-
self.error_code=str
38
-
self.msg=str
39
-
self.cause_err=str
35
+
self.__error_dict= {}
36
+
self.__error_code=str
37
+
self.__msg=str
38
+
self.__cause_err=str
39
+
40
+
defconfig(self, result: dict):
41
+
ifresultisnotNoneandlen(result) >0:
42
+
self.__error_dict=result
43
+
self.__error_code=self.__error_dict['error_code']
44
+
self.__msg=self.__error_dict['error_message']
45
+
self.__cause_err=self.__error_dict['errors']
46
+
47
+
@property
48
+
deferror_code(self):
49
+
"""
50
+
:return: error_code as int
51
+
"""
52
+
returnself.__error_code
53
+
54
+
@property
55
+
deferror_message(self):
56
+
"""
57
+
:return: error_message
58
+
"""
59
+
returnself.__msg
60
+
61
+
@property
62
+
deferror(self):
63
+
"""
64
+
:return: error dict
65
+
"""
66
+
returnself.__cause_err
67
+
68
+
@property
69
+
deferror_info(self) ->dict:
70
+
71
+
"""
72
+
:return: dict, error information
73
+
"""
74
+
returnself.__error_dict
40
75
41
76
errors_str= {
42
77
43
-
'error_invalid_json': "Please provide valid JSON.",
44
-
'error_message_stack_api_key_is_null': "Stack api key can not be null.",
45
-
'error_form_name': "Please set contentType name.",
46
-
'error_stack_access_token_is_null': "Access token can not be null.",
47
-
'error_stack_environment_is_null': "Environment can not be null.",
48
-
'Error_Connection_Error': "Connection error",
49
-
'Error_Auth_Failure_Error': "Authentication Not present.",
50
-
'Error_Parse_Error': "Parsing Error.",
51
-
'Error_Server_Error': "Server interaction went wrong, Please try again.",
52
-
'Error_Default': "Oops! Something went wrong. Please try again.",
53
-
'Error_No_Network': "Network not available.",
54
-
'Error_Called_Default_Method': "You must called Contentstack.stack() first",
55
-
'Error_Query_Filter_Exception': "Please provide valid params."
78
+
'invalid_json': "Please provide valid JSON.",
79
+
'api_key_is_none': "Stack api key can not be None.",
80
+
'empty_content_type': "Please set contentType name.",
81
+
'access_token_error': "Access token can not be None.",
82
+
'environment_error': "Environment can not be None.",
83
+
'connection_error': "Connection error",
84
+
'auth_failure': "Authentication Not present.",
85
+
'parse_error': "Parsing Error.",
86
+
'server_error': "Server interaction went wrong, Please try again.",
87
+
'error_default': "Oops! Something went wrong. Please try again.",
88
+
'no_network': "Network not available.",
89
+
'query_error': "Please provide valid params."
56
90
}
57
91
58
-
error_code= {
92
+
__error_code= {
59
93
60
94
400: "The request was incorrect or corrupted.",
61
95
401: "The login credentials are invalid.",
@@ -69,70 +103,19 @@ def __init__(self):
69
103
504: "A server did not receive a timely response from another server that it was accessing while attempting to load the web page or fill another request by the browser."
70
104
}
71
105
72
-
exceptions= {
73
-
74
-
AssertionError: "Raised when the assert statement fails.",
75
-
AttributeError: "Raised on the attribute assignment or reference fails.",
76
-
EOFError: "Raised when the input() function hits the end-of-file condition.",
77
-
FloatingPointError: "Raised when a floating point operation fails.",
78
-
GeneratorExit: "Raised when a generator's close() method is called.",
79
-
ImportError: "Raised when the imported module is not found.",
80
-
IndexError: "Raised when the index of a sequence is out of range.",
81
-
KeyError: "Raised when a key is not found in a dictionary.",
82
-
KeyboardInterrupt: "Raised when the user hits the interrupt key (Ctrl+c or delete).",
83
-
MemoryError: "Raised when an operation runs out of memory.",
84
-
NameError: "Raised when a variable is not found in the local or global scope.",
85
-
NotImplementedError: "Raised by abstract methods.",
86
-
OSError: "Raised when a system operation causes a system-related error.",
87
-
OverflowError: "Raised when the result of an arithmetic operation is too large to be represented.",
88
-
ReferenceError: "Raised when a weak reference proxy is used to access a garbage collected referent.",
89
-
RuntimeError: "Raised when an error does not fall under any other category.",
90
-
StopIteration: "Raised by the next() function to indicate that there is no further item to be returned by the iterator.",
91
-
SyntaxError: "Raised by the parser when a syntax error is encountered.",
92
-
IndentationError: "Raised when there is an incorrect indentation.",
93
-
TabError: "Raised when the indentation consists of inconsistent tabs and spaces.",
94
-
SystemError: "Raised when the interpreter detects internal error.",
95
-
SystemExit: "Raised by the sys.exit() function.",
96
-
TypeError: "Raised when a function or operation is applied to an object of an incorrect type.",
97
-
UnboundLocalError: "Raised when a reference is made to a local variable in a function or method, but no value has been bound to that variable.",
98
-
UnicodeError: "Raised when a Unicode-related encoding or decoding error occurs.",
99
-
UnicodeEncodeError: "Raised when a Unicode-related error occurs during encoding.",
100
-
UnicodeDecodeError: "Raised when a Unicode-related error occurs during decoding.",
101
-
UnicodeTranslateError: "Raised when a Unicode-related error occurs during translation.",
102
-
ValueError: "Raised when a function gets an argument of correct type but improper value.",
103
-
ZeroDivisionError: "Raised when the second operand of a division or module operation is zero."
104
-
105
-
}
106
-
107
-
deferror(self, response: dict) ->tuple:
108
-
ifresponseisnotNoneandisinstance(response, dict):
109
-
self.error_code=response['error_code']
110
-
self.msg=response['error_message']
111
-
self.cause_err=response['errors']
112
-
113
-
returnself.error_code, self.msg, self.cause_err
114
-
115
106
@staticmethod
116
107
deflogging_config(level):
108
+
117
109
print('level '+level)
118
110
119
111
120
112
classConfigError(Exception):
121
-
"""Configuration Error Class"""
122
113
pass
123
114
124
115
125
116
classStackException(Exception):
126
-
"""StackException Class"""
127
117
pass
128
118
129
119
130
120
classNotSupportedException(Exception):
131
-
""" exception is thrown when something is not supported by the API."""
132
121
pass
133
-
134
-
135
-
classretry_request(object):
136
-
"""
137
-
Decorator to retry function calls in case they raise rate limit exceptions
0 commit comments