@@ -558,28 +558,48 @@ def _raise_for_status(
558
558
return
559
559
elif status_code == http .HTTPStatus .FORBIDDEN :
560
560
raise AuthorizationException (
561
- f"Authorization failure, check auth_key{ message } "
561
+ f"Authorization failure, check auth_key{ message } " ,
562
+ http_status_code = status_code ,
562
563
)
563
564
elif status_code == self ._HTTP_STATUS_QUOTA_EXCEEDED :
564
565
raise QuotaExceededException (
565
- f"Quota for this billing period has been exceeded{ message } "
566
+ f"Quota for this billing period has been exceeded{ message } " ,
567
+ http_status_code = status_code ,
566
568
)
567
569
elif status_code == http .HTTPStatus .NOT_FOUND :
568
570
if glossary :
569
- raise GlossaryNotFoundException (f"Glossary not found{ message } " )
570
- raise DeepLException (f"Not found, check server_url{ message } " )
571
+ raise GlossaryNotFoundException (
572
+ f"Glossary not found{ message } " ,
573
+ http_status_code = status_code ,
574
+ )
575
+ raise DeepLException (
576
+ f"Not found, check server_url{ message } " ,
577
+ http_status_code = status_code ,
578
+ )
571
579
elif status_code == http .HTTPStatus .BAD_REQUEST :
572
- raise DeepLException (f"Bad request{ message } " )
580
+ raise DeepLException (
581
+ f"Bad request{ message } " , http_status_code = status_code
582
+ )
573
583
elif status_code == http .HTTPStatus .TOO_MANY_REQUESTS :
574
584
raise TooManyRequestsException (
575
585
"Too many requests, DeepL servers are currently experiencing "
576
- f"high load{ message } "
586
+ f"high load{ message } " ,
587
+ should_retry = True ,
588
+ http_status_code = status_code ,
577
589
)
578
590
elif status_code == http .HTTPStatus .SERVICE_UNAVAILABLE :
579
591
if downloading_document :
580
- raise DocumentNotReadyException (f"Document not ready{ message } " )
592
+ raise DocumentNotReadyException (
593
+ f"Document not ready{ message } " ,
594
+ should_retry = True ,
595
+ http_status_code = status_code ,
596
+ )
581
597
else :
582
- raise DeepLException (f"Service unavailable{ message } " )
598
+ raise DeepLException (
599
+ f"Service unavailable{ message } " ,
600
+ should_retry = True ,
601
+ http_status_code = status_code ,
602
+ )
583
603
else :
584
604
status_name = (
585
605
http .client .responses [status_code ]
@@ -588,7 +608,9 @@ def _raise_for_status(
588
608
)
589
609
raise DeepLException (
590
610
f"Unexpected status code: { status_code } { status_name } , "
591
- f"content: { content } ."
611
+ f"content: { content } ." ,
612
+ should_retry = False ,
613
+ http_status_code = status_code ,
592
614
)
593
615
594
616
def _check_valid_languages (
0 commit comments