@@ -109,17 +109,12 @@ def _search_post(self, query: str, token_budget: int) -> requests.Response:
109
109
110
110
def _extract_global_field (self , data : dict [str , Any ], field_path : list [str ]) -> Any :
111
111
"""Extract a global field from the API response using a path"""
112
- current_data = data
113
- for path_key in field_path :
114
- try :
115
- if isinstance (current_data , dict ):
116
- current_data = current_data .get (path_key )
117
- else :
118
- return None
119
- except Exception as e :
120
- logger .error (f"Error extracting global field: { e } " )
112
+ current = data
113
+ for key in field_path :
114
+ if not isinstance (current , dict ) or key not in current :
121
115
return None
122
- return current_data
116
+ current = current [key ]
117
+ return current
123
118
124
119
def _extract_field_value (self , source : dict [str , Any ], field_key : str ) -> str :
125
120
"""Safely extract a field value from a source dictionary"""
@@ -130,16 +125,13 @@ def _extract_field_value(self, source: dict[str, Any], field_key: str) -> str:
130
125
131
126
def _navigate_to_results (self , data : dict [str , Any ]) -> list [dict [str , Any ]]:
132
127
"""Navigate to results list using the configured path"""
133
- current_data = data
134
-
135
- for path_key in self .config .results_path :
136
- if not current_data :
137
- logger .error (f"Path '{ path_key } ' not found in data" )
128
+ current = data
129
+ for key in self .config .results_path :
130
+ if not isinstance (current , dict ) or key not in current :
138
131
return []
139
- current_data = current_data . get ( path_key )
132
+ current = current [ key ]
140
133
141
- # API responses should return a list of results
142
- return current_data or []
134
+ return current if isinstance (current , list ) else []
143
135
144
136
def _extract_results (self , data : dict [str , Any ]) -> list [InternetSearchResult ]:
145
137
"""Extract results from API response based on provider configuration"""
0 commit comments