22
33import transifex
44
5+ from .exceptions import DownloadException , UploadException
56from .jsonapi import JsonApi
67from .jsonapi import Resource as JsonApiResource
7- from .jsonapi .exceptions import JsonApiException
88
99
1010class DownloadMixin (object ):
@@ -19,16 +19,11 @@ def download(cls, interval=5, *args, **kwargs):
1919 download = cls .create (* args , ** kwargs )
2020 while True :
2121 if hasattr (download , "errors" ) and len (download .errors ) > 0 :
22- errors = [
23- {
24- "code" : e ["code" ],
25- "detail" : e ["detail" ],
26- "title" : e ["detail" ],
27- "status" : "409" ,
28- }
29- for e in download .errors
30- ]
31- raise JsonApiException (409 , errors )
22+ # The way Transifex APIv3 works right now, only one error will be
23+ # returned, so we give priority to the first error's 'detail' field. If
24+ # more errors are included in the future, the user can inspect the
25+ # exception's second argument
26+ raise DownloadException (download .error [0 ]["detail" ], download .errors )
3227 if download .redirect :
3328 return download .redirect
3429 time .sleep (interval )
@@ -54,16 +49,11 @@ def upload(cls, content, interval=5, **data):
5449
5550 while True :
5651 if hasattr (upload , "errors" ) and len (upload .errors ) > 0 :
57- errors = [
58- {
59- "code" : e ["code" ],
60- "detail" : e ["detail" ],
61- "title" : e ["detail" ],
62- "status" : "409" ,
63- }
64- for e in upload .errors
65- ]
66- raise JsonApiException (409 , errors )
52+ # The way Transifex APIv3 works right now, only one error will be
53+ # returned, so we give priority to the first error's 'detail' field. If
54+ # more errors are included in the future, the user can inspect the
55+ # exception's second argument
56+ raise UploadException (upload .errors [0 ]["detail" ], upload .errors )
6757
6858 if upload .redirect :
6959 return upload .follow ()
0 commit comments