Skip to content

Commit 9ae5d5a

Browse files
committed
Use an explicit exception to tell the conversion is in progress
1 parent 33bfe35 commit 9ae5d5a

File tree

3 files changed

+7
-3
lines changed

3 files changed

+7
-3
lines changed

convertapi/client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def handle_response(self, r):
5454
try:
5555
return r.json()
5656
except simplejson.errors.JSONDecodeError as e:
57-
raise ApiError({'message': 'Conversion in progress'})
57+
raise AsyncConversionInProgress
5858

5959
def url(self, path):
6060
return "%s%s?Secret=%s" % (convertapi.base_uri, path, convertapi.api_secret)

convertapi/exceptions.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,7 @@ def __init__(self, result):
1313
def __str__(self):
1414
message = "%s Code: %s. %s" % (self.message, self.code, self.invalid_parameters)
1515
return message.strip()
16+
17+
18+
class AsyncConversionInProgress(BaseError):
19+
pass

tests/test_convertapi.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ def test_polling_too_fast_and_getting_202_accepted(self):
105105
convert_result = convertapi.async_convert('pdf', { 'File': 'examples/files/test.docx' })
106106
try:
107107
convertapi.async_poll(convert_result.response['JobId'])
108-
except convertapi.ApiError:
108+
except convertapi.AsyncConversionInProgress:
109109
pass
110110
else:
111111
raise AssertionError
@@ -116,7 +116,7 @@ def test_polling_too_fast_and_getting_202_accepted(self):
116116
def get_poll_result(job_id, retry_count=5):
117117
try:
118118
result = convertapi.async_poll(job_id)
119-
except convertapi.ApiError:
119+
except convertapi.AsyncConversionInProgress:
120120
if retry_count > 0:
121121
time.sleep((1 + 0.1) ** (5 - retry_count) - 1)
122122
return get_poll_result(job_id, retry_count=retry_count - 1)

0 commit comments

Comments
 (0)