@@ -475,16 +475,16 @@ def _parse_response(
475
475
if resp_content_type and "audio" in resp_content_type :
476
476
return FileHTTPResponse (response ) # type: ignore
477
477
478
- code , msg , data = self ._parse_requests_code_msg (method , url , response , data_field )
478
+ code , msg , debug_url , data = self ._parse_requests_code_msg (method , url , response , data_field )
479
479
480
480
if code is not None and code > 0 :
481
481
log_warning ("request %s#%s failed, logid=%s, code=%s, msg=%s" , method , url , logid , code , msg )
482
- raise CozeAPIError (code , msg , logid )
482
+ raise CozeAPIError (code , msg , logid , debug_url )
483
483
elif code is None and msg != "" :
484
484
log_warning ("request %s#%s failed, logid=%s, msg=%s" , method , url , logid , msg )
485
485
if msg in COZE_PKCE_AUTH_ERROR_TYPE_ENUMS :
486
486
raise CozePKCEAuthError (CozePKCEAuthErrorType (msg ), logid )
487
- raise CozeAPIError (code , msg , logid )
487
+ raise CozeAPIError (code , msg , logid , debug_url )
488
488
if isinstance (cast , List ):
489
489
item_cast = cast [0 ]
490
490
return [item_cast .model_validate (item ) for item in data ]
@@ -502,7 +502,7 @@ def _parse_response(
502
502
503
503
def _parse_requests_code_msg (
504
504
self , method : str , url : str , response : Response , data_field : str = "data"
505
- ) -> Tuple [Optional [int ], str , Any ]:
505
+ ) -> Tuple [Optional [int ], str , Optional [ str ], Any ]:
506
506
try :
507
507
response .read ()
508
508
body = response .json ()
@@ -514,18 +514,19 @@ def _parse_requests_code_msg(
514
514
response .text ,
515
515
response .headers .get ("x-tt-logid" ),
516
516
) from e
517
-
517
+ debug_url = body . get ( "debug_url" )
518
518
if "code" in body and "msg" in body and int (body ["code" ]) > 0 :
519
- return int (body ["code" ]), body ["msg" ], body .get (data_field )
519
+ return int (body ["code" ]), body ["msg" ], debug_url , body .get (data_field )
520
520
if "error_code" in body and body ["error_code" ] in COZE_PKCE_AUTH_ERROR_TYPE_ENUMS :
521
- return None , body ["error_code" ], None
521
+ return None , body ["error_code" ], debug_url , None
522
522
if "error_message" in body and body ["error_message" ] != "" :
523
- return None , body ["error_message" ], None
523
+ return None , body ["error_message" ], debug_url , None
524
524
if data_field in body or "debug_url" in body :
525
525
if "first_id" in body :
526
526
return (
527
527
0 ,
528
528
"" ,
529
+ debug_url ,
529
530
{
530
531
"first_id" : body ["first_id" ],
531
532
"has_more" : body ["has_more" ],
@@ -537,13 +538,14 @@ def _parse_requests_code_msg(
537
538
return (
538
539
0 ,
539
540
"" ,
541
+ debug_url ,
540
542
{
541
543
"data" : body .get (data_field ),
542
- "debug_url" : body . get ( " debug_url" ) or "" ,
544
+ "debug_url" : debug_url or "" ,
543
545
"execute_id" : body .get ("execute_id" ) or None ,
544
546
},
545
547
)
546
- return 0 , "" , body [data_field ]
548
+ return 0 , "" , debug_url , body [data_field ]
547
549
if data_field == "data.data" :
548
- return 0 , "" , body ["data" ]["data" ]
549
- return 0 , "" , body
550
+ return 0 , "" , debug_url , body ["data" ]["data" ]
551
+ return 0 , "" , debug_url , body
0 commit comments