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