Skip to content

Commit 2f9fd3c

Browse files
committed
Avoid a JSONDecodeError when polling too earlier
1 parent 6f1b901 commit 2f9fd3c

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

convertapi/client.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import requests
22
import convertapi
3+
import simplejson
34

45
from io import BytesIO
56
from .exceptions import *
@@ -50,7 +51,10 @@ def handle_response(self, r):
5051
except ValueError:
5152
raise e
5253

53-
return r.json()
54+
try:
55+
return r.json()
56+
except simplejson.errors.JSONDecodeError as e:
57+
raise ApiError({'message': 'Conversion in progress'})
5458

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

tests/test_convertapi.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,15 @@ def test_polling_of_invalid_job_id(self):
101101
else:
102102
raise AssertionError
103103

104+
def test_polling_too_fast_and_getting_202_accepted(self):
105+
convert_result = convertapi.async_convert('pdf', { 'File': 'examples/files/test.docx' })
106+
try:
107+
convertapi.async_poll(convert_result.response['JobId'])
108+
except convertapi.ApiError:
109+
pass
110+
else:
111+
raise AssertionError
112+
104113

105114
def get_poll_result(job_id, retry_count=5):
106115
try:

0 commit comments

Comments
 (0)