@@ -197,7 +197,6 @@ def http_request(
197197 stream = streamed ,
198198 ** opts ,
199199 )
200-
201200 self ._check_redirects (result .response )
202201
203202 if 200 <= result .status_code < 300 :
@@ -225,25 +224,8 @@ def http_request(
225224 error_json = result .json ()
226225 # Common fields
227226 if isinstance (error_json , dict ):
228- # First priority: look for a 'message' field (most specific)
229- if "message" in error_json :
230- error_message = error_json .get ("message" )
231- elif "execution_message" in error_json :
232- error_message = error_json .get ("execution_message" )
233- elif "error" in error_json :
234- err = error_json .get ("error" )
235- if isinstance (err , dict ) and "message" in err :
236- error_message = err .get ("message" )
237- elif err and err not in [
238- "Internal Server Error" ,
239- "Bad Request" ,
240- "Not Found" ,
241- "Unauthorized" ,
242- "Forbidden" ,
243- ]:
244- # Only use 'error' field if it's not a generic HTTP status
245- error_message = str (err )
246- elif "errors" in error_json :
227+ # Check for nested validation errors first (more specific)
228+ if "errors" in error_json :
247229 errs = error_json .get ("errors" )
248230 if isinstance (errs , list ) and errs :
249231 # Join any messages in the list
@@ -254,6 +236,52 @@ def http_request(
254236 else :
255237 messages .append (str (item ))
256238 error_message = "; " .join (messages )
239+ elif isinstance (errs , dict ):
240+ # Handle nested validation errors from OpenBAS
241+ if "children" in errs :
242+ # This is a validation error structure
243+ validation_errors = []
244+ children = errs .get ("children" , {})
245+ for field , field_errors in children .items ():
246+ if (
247+ isinstance (field_errors , dict )
248+ and "errors" in field_errors
249+ ):
250+ field_error_list = field_errors .get (
251+ "errors" , []
252+ )
253+ if field_error_list :
254+ for err_msg in field_error_list :
255+ validation_errors .append (
256+ f"{ field } : { err_msg } "
257+ )
258+ if validation_errors :
259+ base_msg = error_json .get (
260+ "message" , "Validation Failed"
261+ )
262+ error_message = f"{ base_msg } : { '; ' .join (validation_errors )} "
263+ elif isinstance (errs , str ):
264+ error_message = errs
265+
266+ # If no error message from errors field, check other fields
267+ if not error_message :
268+ if "message" in error_json :
269+ error_message = error_json .get ("message" )
270+ elif "execution_message" in error_json :
271+ error_message = error_json .get ("execution_message" )
272+ elif "error" in error_json :
273+ err = error_json .get ("error" )
274+ if isinstance (err , dict ) and "message" in err :
275+ error_message = err .get ("message" )
276+ elif err and err not in [
277+ "Internal Server Error" ,
278+ "Bad Request" ,
279+ "Not Found" ,
280+ "Unauthorized" ,
281+ "Forbidden" ,
282+ ]:
283+ # Only use 'error' field if it's not a generic HTTP status
284+ error_message = str (err )
257285 elif isinstance (error_json , str ):
258286 error_message = error_json
259287 # Fallback to serialized json if we still have nothing
0 commit comments