|
4 | 4 |
|
5 | 5 | from . import http_client, util |
6 | 6 | from .exceptions import ( |
| 7 | + DocumentNotReadyException, |
7 | 8 | GlossaryNotFoundException, |
8 | 9 | QuotaExceededException, |
9 | 10 | TooManyRequestsException, |
@@ -494,6 +495,7 @@ def _raise_for_status( |
494 | 495 | content: str, |
495 | 496 | json: Optional[dict], |
496 | 497 | glossary: bool = False, |
| 498 | + downloading_document: bool = False, |
497 | 499 | ): |
498 | 500 | message = "" |
499 | 501 | if json is not None and "message" in json: |
@@ -522,6 +524,11 @@ def _raise_for_status( |
522 | 524 | "Too many requests, DeepL servers are currently experiencing " |
523 | 525 | f"high load{message}" |
524 | 526 | ) |
| 527 | + elif status_code == http.HTTPStatus.SERVICE_UNAVAILABLE: |
| 528 | + if downloading_document: |
| 529 | + raise DocumentNotReadyException(f"Document not ready{message}") |
| 530 | + else: |
| 531 | + raise DeepLException(f"Service unavailable{message}") |
525 | 532 | else: |
526 | 533 | status_name = ( |
527 | 534 | http.client.responses[status_code] |
@@ -939,9 +946,9 @@ def translate_document_download( |
939 | 946 | url, data=data, stream=True |
940 | 947 | ) |
941 | 948 |
|
942 | | - if status_code == http.HTTPStatus.SERVICE_UNAVAILABLE: |
943 | | - raise DeepLException("Document not ready for download") |
944 | | - self._raise_for_status(status_code, "<file>", json) |
| 949 | + self._raise_for_status( |
| 950 | + status_code, "<file>", json, downloading_document=True |
| 951 | + ) |
945 | 952 |
|
946 | 953 | if output_file: |
947 | 954 | for chunk in response.iter_content(chunk_size=chunk_size): |
|
0 commit comments