55#min-similarity-lines=10
66import logging
77from urllib import parse
8+ from contentstack .error_messages import ErrorMessages
89
910from contentstack .deep_merge_lp import DeepMergeMixin
1011from contentstack .entryqueryable import EntryQueryable
@@ -49,7 +50,7 @@ def environment(self, environment):
4950 ------------------------------
5051 """
5152 if environment is None :
52- raise KeyError ('Kindly provide a valid environment' )
53+ raise KeyError (ErrorMessages . INVALID_ENVIRONMENT )
5354 self .http_instance .headers ['environment' ] = environment
5455 return self
5556
@@ -72,7 +73,7 @@ def version(self, version):
7273 ------------------------------
7374 """
7475 if version is None :
75- raise KeyError ('Kindly provide a valid version' )
76+ raise KeyError (ErrorMessages . INVALID_VERSION )
7677 self .entry_param ['version' ] = version
7778 return self
7879
@@ -94,7 +95,7 @@ def param(self, key, value):
9495 -----------------------------
9596 """
9697 if None in (key , value ) and not isinstance (key , str ):
97- raise ValueError ('Kindly provide valid key and value arguments' )
98+ raise ValueError (ErrorMessages . INVALID_KEY_VALUE_ARGS )
9899 self .entry_param [key ] = value
99100 return self
100101
@@ -113,7 +114,7 @@ def include_fallback(self):
113114 >>> result = entry.fetch()
114115 ----------------------------
115116 """
116- print ('Requesting fallback....' )
117+ print (ErrorMessages . REQUESTING_FALLBACK )
117118 self .entry_param ['include_fallback' ] = 'true'
118119 return self
119120
@@ -157,8 +158,7 @@ def __get_base_url(self, endpoint=''):
157158 if endpoint is not None and endpoint .strip (): # .strip() removes leading/trailing whitespace
158159 self .http_instance .endpoint = endpoint
159160 if None in (self .http_instance , self .content_type_id , self .entry_uid ):
160- raise KeyError (
161- 'Provide valid http_instance, content_type_uid or entry_uid' )
161+ raise KeyError (ErrorMessages .INVALID_KEY_OR_VALUE )
162162 url = f'{ self .http_instance .endpoint } /content_types/{ self .content_type_id } /entries/{ self .entry_uid } '
163163 return url
164164
@@ -217,12 +217,12 @@ def _merged_response(self):
217217 if not isinstance (lp_entry , list ):
218218 lp_entry = [lp_entry ] # Wrap in a list if it's a dict
219219 if not all (isinstance (item , dict ) for item in entry_response ):
220- raise TypeError (f"entry_response must be a list of dictionaries. Got: { entry_response } " )
220+ raise TypeError (ErrorMessages . INVALID_ENTRY_RESPONSE )
221221 if not all (isinstance (item , dict ) for item in lp_entry ):
222- raise TypeError (f"lp_entry must be a list of dictionaries. Got: { lp_entry } " )
222+ raise TypeError (ErrorMessages . INVALID_LP_ENTRY )
223223 merged_response = DeepMergeMixin (entry_response , lp_entry ).to_dict () # Convert to dictionary
224224 return merged_response # Now correctly returns a dictionary
225- raise ValueError ("Missing required keys in live_preview data" )
225+ raise ValueError (ErrorMessages . MISSING_LIVE_PREVIEW_KEYS )
226226
227227 def variants (self , variant_uid : str | list [str ], params : dict = None ):
228228 """
0 commit comments