@@ -558,28 +558,48 @@ def _raise_for_status(
558558 return
559559 elif status_code == http .HTTPStatus .FORBIDDEN :
560560 raise AuthorizationException (
561- f"Authorization failure, check auth_key{ message } "
561+ f"Authorization failure, check auth_key{ message } " ,
562+ http_status_code = status_code ,
562563 )
563564 elif status_code == self ._HTTP_STATUS_QUOTA_EXCEEDED :
564565 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 ,
566568 )
567569 elif status_code == http .HTTPStatus .NOT_FOUND :
568570 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+ )
571579 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+ )
573583 elif status_code == http .HTTPStatus .TOO_MANY_REQUESTS :
574584 raise TooManyRequestsException (
575585 "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 ,
577589 )
578590 elif status_code == http .HTTPStatus .SERVICE_UNAVAILABLE :
579591 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+ )
581597 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+ )
583603 else :
584604 status_name = (
585605 http .client .responses [status_code ]
@@ -588,7 +608,9 @@ def _raise_for_status(
588608 )
589609 raise DeepLException (
590610 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 ,
592614 )
593615
594616 def _check_valid_languages (
0 commit comments