66import json
77import logging
88import warnings
9+ from contentstack .error_messages import ErrorMessages
910from urllib import parse
1011
1112from contentstack .basequery import BaseQuery
@@ -44,8 +45,7 @@ def __init__(self, http_instance, content_type_uid, logger=None):
4445 self .content_type_uid = content_type_uid
4546 self .http_instance = http_instance
4647 if self .content_type_uid is None :
47- raise PermissionError (
48- 'You are not allowed here without content_type_uid' )
48+ raise PermissionError (ErrorMessages .CONTENT_TYPE_UID_REQUIRED )
4949 self .base_url = f'{ self .http_instance .endpoint } /content_types/{ self .content_type_uid } /entries'
5050 self .base_url = self .__get_base_url ()
5151 self .logger = logger or logging .getLogger (__name__ )
@@ -54,8 +54,7 @@ def __get_base_url(self, endpoint=''):
5454 if endpoint is not None and endpoint .strip (): # .strip() removes leading/trailing whitespace
5555 self .http_instance .endpoint = endpoint
5656 if None in (self .http_instance , self .content_type_uid ):
57- raise KeyError (
58- 'Provide valid http_instance, content_type_uid or entry_uid' )
57+ raise KeyError (ErrorMessages .INVALID_KEY_OR_VALUE )
5958 url = f'{ self .http_instance .endpoint } /content_types/{ self .content_type_uid } /entries'
6059
6160 return url
@@ -138,7 +137,7 @@ def search(self, value: str):
138137 >>> result = query.find()
139138 -------------------------------------
140139 """
141- warnings .warn ('deprecated in 1.7.0, Use regex function instead' )
140+ warnings .warn (ErrorMessages . DEPRECATED_SEARCH )
142141 if value is not None :
143142 self .query_params ["typeahead" ] = value
144143 return self
@@ -170,7 +169,7 @@ def where_in(self, key: str, query_object):
170169 self .query_params ["query" ] = {
171170 key : {"$in_query" : query_object .parameters }}
172171 else :
173- raise ValueError ('Invalid Key or Value provided' )
172+ raise ValueError (ErrorMessages . INVALID_KEY_OR_VALUE )
174173 return self
175174
176175 def where_not_in (self , key , query_object ):
@@ -200,7 +199,7 @@ def where_not_in(self, key, query_object):
200199 self .query_params ["query" ] = {
201200 key : {"$nin_query" : query_object .parameters }}
202201 else :
203- raise ValueError ('Invalid Key or Value provided' )
202+ raise ValueError (ErrorMessages . INVALID_KEY_OR_VALUE )
204203 return self
205204
206205 def include_fallback (self ):
@@ -330,14 +329,14 @@ def __execute_network_call(self):
330329 try :
331330 response = json .loads (response ) # Convert JSON string to dictionary
332331 except json .JSONDecodeError as e :
333- print (f"JSON decode error: { e } " )
332+ print (ErrorMessages . INVALID_JSON . format ( error = str ( e )) )
334333 return {"error" : "Invalid JSON response" } # Return an error dictionary
335334
336335 if self .http_instance .live_preview is not None and 'errors' not in response :
337336 if 'entries' in response :
338337 self .http_instance .live_preview ['entry_response' ] = response ['entries' ][0 ] # Get first entry
339338 else :
340- print (f"Error: 'entries' key missing in response: { response } " )
339+ print (ErrorMessages . MISSING_ENTRIES_KEY )
341340 return {"error" : "'entries' key missing in response" }
342341 return self ._merged_response ()
343342 return response
@@ -356,7 +355,7 @@ def _impl_live_preview(self):
356355 if 'entry' in lp_resp :
357356 self .http_instance .live_preview ['lp_response' ] = {'entry' : lp_resp ['entry' ]} # Extract entry
358357 else :
359- print (f"Warning: Missing 'entry' key in lp_response: { lp_resp } " )
358+ print (ErrorMessages . MISSING_ENTRY_KEY )
360359 return None
361360 return None
362361
@@ -368,4 +367,4 @@ def _merged_response(self):
368367 merged_response = DeepMergeMixin (entry_response , lp_response )
369368 return merged_response # Return the merged dictionary
370369
371- raise ValueError ("Missing required keys in live_preview data" )
370+ raise ValueError (ErrorMessages . MISSING_LIVE_PREVIEW_KEYS )
0 commit comments