-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #99 from transifex/down_up_load_exceptions
Refactor transifex.api's exceptions for down/uploads
- Loading branch information
Showing
2 changed files
with
46 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
class FileExchangeException(Exception): | ||
def __init__(self, message, errors): | ||
super().__init__(message, errors) | ||
|
||
@property | ||
def message(self): | ||
return self.args[0] | ||
|
||
@property | ||
def errors(self): | ||
return self.args[1] | ||
|
||
def __str__(self): | ||
"""We expect Transifex APIv3 to only return one error during a file exchange. | ||
Even though for future compatibility we include the full list of errors in the | ||
exception objects, we override 'str' so that if someone does: | ||
>>> try: | ||
... transifex_api.ResourceStringsAsyncUpload(...) | ||
... except UploadException as e: | ||
... print(f"Upload error: {e}") | ||
We want the first error's 'detail' field to appear. The full error list | ||
can still be accessed via the second argument. | ||
""" | ||
|
||
return self.message | ||
|
||
|
||
class DownloadException(FileExchangeException): | ||
pass | ||
|
||
|
||
class UploadException(FileExchangeException): | ||
pass |