Skip to content

Commit 91aa699

Browse files
Add example for document exceptions in readme
1 parent bc5857f commit 91aa699

1 file changed

Lines changed: 20 additions & 7 deletions

File tree

README.md

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,25 @@ print(result[1].text) # "How are you?"
6060
print(result[1].detected_source_lang) # "ES"
6161

6262
# Translate a formal document from English to German
63-
translator.translate_document_from_filepath(
64-
"Instruction Manual.docx",
65-
"Bedienungsanleitung.docx",
66-
target_lang="DE",
67-
formality="more"
68-
)
63+
try:
64+
translator.translate_document_from_filepath(
65+
"Instruction Manual.docx",
66+
"Bedienungsanleitung.docx",
67+
target_lang="DE",
68+
formality="more"
69+
)
70+
except deepl.DocumentTranslationException as error:
71+
# If an error occurs during translate_document_from_filepath() or
72+
# translate_document() and after the document was already uploaded, a
73+
# DocumentTranslationException is raised. The document_handle property
74+
# contains the document handle to later retrieve the document or contact
75+
# DeepL support.
76+
doc_id = error.document_handle.id
77+
doc_key = error.document_handle.key
78+
print(f"Error after uploading document ${error}, id: ${doc_id} key: ${doc_key}")
79+
except deepl.DeepLException as error:
80+
# Errors during upload raise a DeepLException
81+
print(error)
6982

7083
# Glossaries allow you to customize your translations
7184
glossary_en_to_de = translator.create_glossary(
@@ -108,7 +121,7 @@ for language in translator.get_target_languages():
108121

109122
### Exceptions
110123
All module functions may raise `deepl.DeepLException` or one of its subclasses.
111-
If invalid arguments are provided, they may raise the standard exceptions `ValueError` and `TypeError`.
124+
If invalid arguments are provided, they may raise the standard exceptions `ValueError` and `TypeError`.
112125

113126
### Configuration
114127

0 commit comments

Comments
 (0)